Selection: IF · Seleção: 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.
IF … THEN em uma única linha
- Seleção escolhe o que executar.
- O guia de 2026 coloca
THENna mesma linha que a condição. - O bloco termina em
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.
ELSE é o outro caminho
ELSEexecuta quando a condição éFALSE.- Exatamente um dos dois blocos é executado.
- Instruções aninhadas
IFmantêm o mesmo formato.
DECLARE Mark : INTEGER
Mark ← 72
IF Mark >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
TRUE or FALSE — which block runs? · VERDADEIRO ou FALSO — qual bloco será executado?
IF runs its THEN block when the test is TRUE; ELSE covers every other case. · IF executa seu bloco THEN quando o teste é VERDADEIRO; ELSE cobre todos os outros casos.
Relational operators
=equal,<>not equal,<><=>=.AND,ORandNOTare logic operators. Their operands areBOOLEAN.
Operadores relacionais
=igual,<>diferente,<><=>=.AND,OReNOTsão operadores lógicos. Seus operandos sãoBOOLEAN.
DECLARE N : INTEGER
N ← 7
IF N 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.
AND, OR e NOT
ANDé verdadeiro apenas quando ambos os testes são verdadeiros. Uma nota está no intervalo quando é pelo menos 0 e no máximo 100.ORé verdadeiro quando um ou outro teste é verdadeiro.NOTinverteTRUEeFALSE.- Escreva a variável em ambos os lados.
Mark >= 0 AND Mark <= 100é o teste.Mark >= 0 AND <= 100não é.
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.
Atenção
THENpermanece na linha doIF. O IGCSE 0478 colocaTHENna linha seguinte. Não misture-os.- Em um teste,
=significa "é igual a". Armazenar um valor ainda usa←. "Pass"e"Fail"precisam de aspas.OUTPUT Passprocura um nome chamado Pass.
Common mistakes
- Every
IFneeds anENDIF. ELSEbelongs to theIFabove it, not to a nested one, unless you indent it that way.
Erros comuns
- Todo
IFprecisa de umENDIF. ELSEpertence aoIFacima dele, não a um aninhado, a menos que você o recue dessa forma.
Now you try
- Read a number and choose with
IF…THEN…ELSE…ENDIF.
Agora você tenta
- Leia um número e escolha com
IF…THEN…ELSE…ENDIF.
Read an INTEGER Mark. Output "Pass" when it is at least 50, otherwise "Fail". · Leia um inteiro INTEGER Mark. Imprima "Pass" se for pelo menos 50, caso contrário "Fail".
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Read an INTEGER N. Output positive when it is greater than 0, otherwise not positive. · Leia um inteiro INTEGER N. Imprima positive se for maior que 0, caso contrário not positive.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Read an INTEGER Mark. Output valid when it is from 0 to · até 100 inclusive, using AND. Otherwise output invalid. · Leia um inteiro INTEGER Mark. Imprima valid se estiver de 0 a 100 inclusivo, usando AND. Caso contrário, imprima invalid.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.