2. Selection
Post date: 06-Jan-2015 09:36:48
Selection
In selection control, execution of statements depends on a condition which is either a true or false
There are four types of selection controls. Namely:
- IF.....THEN
- IF.....THEN.....ELSE
- NESTED IF
- CASE SECTION
IF....THEN
The IF....THEN selection is used if only one option is available. All other options are ignored
Format:
IF <condition> THEN
Statements;
ENDIF
Flowchart Sample
IF....THEN....ELSE
This type of selection is suitable where there are two available options
General Format
IF <condition> THEN
Statements;
ELSE
Statements;
EndIF
Flowchart Sample
Nested IF Selection
This type of selection is used where two or more options have to be considered to make a selection.
General Format
IF <condition> THEN
statements
ELSE
IF <condition> THEN
statements
ELSE
IF<condition> THEN
Statements
ELSE
Statements
ENDIF
ENDIF
ENDIF
Flowchart Sample
CASE Construct
This is an alternative to the Nested IF especially where there are several options to choose from. Its preferred because it reduces the many lines of code. However, the boolean expression for the case selection can only be expressed using integers and alphabetic characters only. The General format should be
CASE integer OF or
CASE Char OF
Example:
Case x of
label 1: statement 1
label 2: statement 2
label 3: statement 3
.
.
.
label n: statement n-1
Else
statement
Endcase