Selection: IF · Seleção: IF
IF makes a decision
- Selection chooses what to do, based on a test.
IFruns itsTHENblock only when the test isTRUE.- The block ends at
ENDIF.
IF toma uma decisão
- Seleção escolhe o que fazer, baseado em um teste.
IFexecuta seu blocoTHENapenas quando o teste éTRUE.- O bloco termina em
ENDIF.
DECLARE Age : INTEGER
Age ← 20
IF Age >= 18
THEN
OUTPUT "You may vote"
ENDIF
IF ... ELSE
ELSEgives the path to take when the test isFALSE.- Exactly one of the two blocks runs.
IF ... ELSE
ELSEdefine o caminho a seguir quando o teste éFALSE.- Exatamente um dos dois blocos é executado.
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 é TRUE; ELSE cobre todos os outros casos.
Comparison operators
=equal to,<>not equal to.<><=>=compare sizes.
Operadores de comparação
=igual a,<>não igual a.<><=>=compare tamanhos.
DECLARE N : INTEGER
N ← 7
IF MOD(N, 2) = 0
THEN
OUTPUT "even"
ELSE
OUTPUT "odd"
ENDIF
Watch out
- In a test,
=means "is equal to". (The arrow←is for storing a value.) - Don't forget
THENafter the test andENDIFto close the block.
Atenção
- Em uma prova,
=significa "é igual a". (A seta←é para armazenar um valor.) - Não esqueça
THENapós o teste eENDIFpara fechar o bloco.
Common mistakes
- Write
IF ... THEN ... ELSE ... ENDIF— do not forgetENDIF. - Compare with
=in pseudocode conditions.
Erros comuns
- Escreva
IF ... THEN ... ELSE ... ENDIF— não se esqueça deENDIF. - Compare com
=em condições em pseudocódigo.
Now you try
- Read the input, then choose with
IF ... ELSE ... ENDIF. - Press Check answer to test it.
Agora você tenta
- Leia a entrada, depois escolha com
IF ... ELSE ... ENDIF. - Pressione Check answer para testá-lo.
Read an INTEGER N. If it is greater than 0, output positive, otherwise output not positive. For input 5, output positive. · Leia um INTEGER N. Se for maior que 0, saia positive, caso contrário saia not positive. Para entrada 5, saia positive.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Read a Mark. Output Pass if it is 50 or more, otherwise Fail. For input 40, output Fail. · Leia um Mark. Saia Pass se for 50 ou mais, caso contrário Fail. Para entrada 40, saia Fail.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Read an INTEGER N. Output even if · se N MOD 2 = 0, otherwise odd. For input 8, output even. · Leia um INTEGER N. Saia even se N MOD 2 = 0, caso contrário odd. Para entrada 8, saia even.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.