Control Structures
Three Basic Control Structures
1. Sequence
Instructions executed one after another in order.
INPUT name
INPUT age
OUTPUT "Hello " + name
OUTPUT "You are " + age + " years old"
2. Selection (Decision)
Choosing different paths based on conditions.
IF-THEN-ELSE
IF score >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
IF-THEN-ELSEIF-ELSE
IF score >= 80 THEN
grade ← "A"
ELSEIF score >= 60 THEN
grade ← "B"
ELSEIF score >= 50 THEN
grade ← "C"
ELSE
grade ← "F"
ENDIF
3. Iteration (Loops)
Repeating instructions multiple times.
FOR Loop (Count-controlled)
FOR i ← 1 TO 10
OUTPUT i
ENDFOR
WHILE Loop (Pre-condition)
count ← 0
WHILE count < 5
OUTPUT count
count ← count + 1
ENDWHILE
REPEAT-UNTIL Loop (Post-condition)
REPEAT
INPUT password
UNTIL password = "secret123"
Key Difference
- WHILE: Checks condition BEFORE executing (may never run)
- REPEAT-UNTIL: Checks condition AFTER executing (runs at least once)