Control Structures in BCA: Selection, Iteration, Sequence

undefined
Ms. D.Manopriya, Asst. Prof in BCA
D
A
T
E
 
:
 
2
7
.
0
9
.
2
0
2
2
Control Structures
The selection structure tests a condition, then executes one
sequence of statements instead of another, depending on whether
the condition is true or false.
Acondition is any variable or expression that returns a Boolean
value (TRUE or FALSE).
The iteration structure executes a sequence of statements
repeatedly as long as a condition holds true.
The sequence structure simply executes a sequence of
statements in the order in which they occur.
Ms. D.Manopriya, Asst. Prof in BCA
2
CONDITIONAL CONTROL: IF AND CASE STATEMENTS
Often, it is necessary to take alternative actions depending on
circumstances.
The IF statement lets you execute a sequence of statements
conditionally.
That is, whether the sequence is executed or not depends on the
value of a condition.
There are three forms of IF statements: 
IF-THEN, IF-THEN-ELSE,
and IF-THEN-ELSIF
.
The 
CASE statement
 is a compact way to evaluate a single
condition and choose between many alternative actions.
Ms. D.Manopriya, Asst. Prof in BCA
3
1) IF-THEN Statement
The simplest form of IF statement associates a condition with a
sequence of statements enclosed by the keywords THEN and
END IF (not ENDIF), as follows:
IF condition THEN
   sequence_of_statements
END IF;
The sequence of statements is executed only if the condition is
true. If the condition is false or null, the IF statement does nothing.
In either case, control passes to the next statement.
Ms. D.Manopriya, Asst. Prof in BCA
4
2). IF-THEN-ELSE Statement
The second form of IF statement adds the keyword ELSE
followed by an alternative sequence of statements, as follows:
IF condition THEN
   sequence_of_statements1
ELSE
   sequence_of_statements2
END IF;
The sequence of statements in the ELSE clause is executed only
if the condition is false or null. Thus, the ELSE clause ensures that
a sequence of statements is executed.
Ms. D.Manopriya, Asst. Prof in BCA
5
3).IF-THEN-ELSIF Statement
Sometimes user want to select an action from several mutually
exclusive alternatives.
The third form of IF statement uses the keyword ELSIF (not
ELSEIF) to introduce additional conditions, as follows:
IF condition1 THEN
   sequence_of_statements1
ELSIF condition2 THEN
   sequence_of_statements2
ELSE
   sequence_of_statements3
END IF;
Ms. D.Manopriya, Asst. Prof in BCA
6
4).CASE Statement
Like the IF statement, the CASE
statement selects one sequence
of statements to execute.
However, to select the sequence,
the CASE statement uses a
selector rather than multiple
Boolean expressions.
To compare theIF and CASE
statements, consider the 
following
code that outputs descriptions of
school grades:
IF grade = 'A' THEN
   dbms_output.put_line('Excellent');
ELSIF grade = 'B' THEN
   dbms_output.put_line('Very Good');
ELSIF grade = 'C' THEN
   dbms_output.put_line('Good');
ELSIF grade = 'D' THEN
   dbms_output. put_line('Fair');
ELSIF grade = 'F' THEN
   dbms_output.put_line('Poor');
ELSE
   dbms_output.put_line('No such grade');
END IF;
Ms. D.Manopriya, Asst. Prof in BCA
7
Slide Note
Embed
Share

The BCA department at Sri Vasavi College, Erode, delves into control structures encompassing selection, iteration, and sequence in relational database management systems and Oracle. Ms. D. Manopriya, Assistant Professor, elucidates concepts with examples such as IF-THEN, IF-THEN-ELSE, and IF-THEN-ELSIF statements. Mastering these fundamental structures is essential for efficient programming.

  • BCA
  • Control Structures
  • Sri Vasavi College
  • Oracle
  • RDBMS

Uploaded on Feb 21, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. SRI VASAVI COLLEGE, ERODE. (SELF- FINANCE WING) DEPARTMENT OF COMPUTER APPLICATIONS III - BCA RDBMS & Oracle DATE : 27.09.2022 HANDLED BY: Ms. D.MANOPRIYA, MCA., M.Phil., ASSISTANT PROFESSOR Ms. D.Manopriya, Asst. Prof in BCA

  2. Control Structures The selection structure tests a condition, then executes one sequence of statements instead of another, depending on whether the condition is true or false. Acondition is any variable or expression that returns a Boolean value (TRUE or FALSE). The iteration structure executes a sequence of statements repeatedly as long as a condition holds true. The sequence structure simply executes a sequence of statements in the order in which they occur. Ms. D.Manopriya, Asst. Prof in BCA 2

  3. CONDITIONAL CONTROL: IF AND CASE STATEMENTS Often, it is necessary to take alternative actions depending on circumstances. The IF statement lets you execute a sequence of statements conditionally. That is, whether the sequence is executed or not depends on the value of a condition. There are three forms of IF statements: IF-THEN, IF-THEN-ELSE, and IF-THEN-ELSIF. The CASE statement is a compact way to evaluate a single condition and choose between many alternative actions. Ms. D.Manopriya, Asst. Prof in BCA 3

  4. 1) IF-THEN Statement The simplest form of IF statement associates a condition with a sequence of statements enclosed by the keywords THEN and END IF (not ENDIF), as follows: IF condition THEN sequence_of_statements END IF; The sequence of statements is executed only if the condition is true. If the condition is false or null, the IF statement does nothing. In either case, control passes to the next statement. Ms. D.Manopriya, Asst. Prof in BCA 4

  5. 2). IF-THEN-ELSE Statement The second form of IF statement adds the keyword ELSE followed by an alternative sequence of statements, as follows: IF condition THEN sequence_of_statements1 ELSE sequence_of_statements2 END IF; The sequence of statements in the ELSE clause is executed only if the condition is false or null. Thus, the ELSE clause ensures that a sequence of statements is executed. Ms. D.Manopriya, Asst. Prof in BCA 5

  6. 3).IF-THEN-ELSIF Statement Sometimes user want to select an action from several mutually exclusive alternatives. The third form of IF statement uses the keyword ELSIF (not ELSEIF) to introduce additional conditions, as follows: IF condition1 THEN sequence_of_statements1 ELSIF condition2 THEN sequence_of_statements2 ELSE sequence_of_statements3 END IF; Ms. D.Manopriya, Asst. Prof in BCA 6

  7. 4).CASE Statement IF grade = 'A' THEN dbms_output.put_line('Excellent'); ELSIF grade = 'B' THEN dbms_output.put_line('Very Good'); ELSIF grade = 'C' THEN dbms_output.put_line('Good'); ELSIF grade = 'D' THEN dbms_output. put_line('Fair'); ELSIF grade = 'F' THEN dbms_output.put_line('Poor'); ELSE dbms_output.put_line('No such grade'); END IF; Like the IF statement, the CASE statement selects one sequence of statements to execute. However, to select the sequence, the CASE statement uses a selector rather than multiple Boolean expressions. To compare theIF and CASE statements, consider the following code that outputs descriptions of school grades: Ms. D.Manopriya, Asst. Prof in BCA 7

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#