Selection: IF
IF … THEN on one line
- Selection chooses what to run.
- The 2026 guide puts
THENon the same line as the condition. - The block ends at
ENDIF.
DECLARE Age : INTEGER
Age ← 20
IF Age >= 18 THEN
OUTPUT "You may vote"
ENDIF
ELSE is the other path
ELSEruns when the condition isFALSE.- Exactly one of the two blocks runs.
- Nested
IFstatements keep the same shape.
DECLARE Mark : INTEGER
Mark ← 72
IF Mark >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
TRUE or FALSE — which block runs?
IF runs its THEN block when the test is TRUE; ELSE covers every other case.
Relational operators
=equal,<>not equal,<><=>=.AND,ORandNOTare logic operators. Their operands areBOOLEAN.
DECLARE Number : INTEGER
Number ← 7
IF Number MOD 2 = 0 THEN
OUTPUT "even"
ELSE
OUTPUT "odd"
ENDIF
AND, OR and NOT
ANDis true only when both tests are true. A mark is in range when it is at least 0 and at most 100.ORis true when either test is true.NOTflipsTRUEandFALSE.- Write the variable on both sides.
Mark >= 0 AND Mark <= 100is the test.Mark >= 0 AND <= 100is not.
DECLARE Mark : INTEGER
Mark ← 80
IF Mark >= 0 AND Mark <= 100 THEN
OUTPUT "valid"
ELSE
OUTPUT "invalid"
ENDIF
Watch out
THENstays on theIFline. IGCSE 0478 putsTHENon the following line. Do not mix them.- In a test,
=means "is equal to". Storing a value still uses←. "Pass"and"Fail"need quotes.OUTPUT Passlooks up a name called Pass.
Common mistakes
- Every
IFneeds anENDIF. - An
ELSEbelongs to the nearestIFthat has not reached itsENDIFyet. Indentation shows this to the reader; theENDIFs decide it.
Now you try
- Read a number and choose with
IF…THEN…ELSE…ENDIF.
Independent transfer
The final task has no supplied algorithm. Plan its inputs, processing and outputs, then solve it before opening support. Check more than the sample case.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Read an INTEGER Mark. Output "Pass" when it is at least 50, otherwise "Fail".
Click Run to see the output here.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Read an INTEGER Number. Output positive when it is greater than 0, otherwise not positive.
Click Run to see the output here.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
Read an INTEGER Mark. Output valid when it is from 0 to 100 inclusive, using AND. Otherwise output invalid.
Click Run to see the output here.
Difficulty 3/5 · 200 coins + a small bonus on first completion today
Read integer LengthValue. Output allowed for the inclusive range 5 to 12, otherwise refused.
Click Run to see the output here.