Условие: 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 или FALSE — какой блок выполнится?
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.
Сложность 1/5 · 100 монет + небольшой бонус за первое завершение сегодня
Read an INTEGER Mark. Output "Pass" when it is at least 50, otherwise "Fail".
Нажмите Запустить, чтобы увидеть результат здесь.
Сложность 1/5 · 100 монет + небольшой бонус за первое завершение сегодня
Read an INTEGER Number. Output positive when it is greater than 0, otherwise not positive.
Нажмите Запустить, чтобы увидеть результат здесь.
Сложность 1/5 · 100 монет + небольшой бонус за первое завершение сегодня
Read an INTEGER Mark. Output valid when it is from 0 до 100 inclusive, using AND. Otherwise output invalid.
Нажмите Запустить, чтобы увидеть результат здесь.
Сложность 3/5 · 200 монет + небольшой бонус за первое завершение сегодня
Read integer LengthValue. Output allowed for the inclusive range 5 to 12, otherwise refused.
Нажмите Запустить, чтобы увидеть результат здесь.