Nested decisions · Decisões aninhadas
One mark, three outcomes
- A mark of 80 or more is a distinction, 50 or more is a pass, and anything lower is a fail.
- One
IFhas two paths. The second decision goes inside theELSE, as its ownIF. - Each
IFhas its ownENDIF. Indent the inner one so you can see whichELSEit belongs to.
Uma nota, três resultados
- Uma nota de 80 ou mais é distinção, 50 ou mais é aprovação, e qualquer valor abaixo é reprovação.
- Um
IFtem dois caminhos. A segunda decisão vai dentro doELSE, como seu próprioIF. - Cada
IFtem seu próprioENDIF. Indente o interno para ver a qualELSEele pertence.
DECLARE Mark : INTEGER
Mark ← 72
IF Mark >= 80
THEN
OUTPUT "Distinction"
ELSE
IF Mark >= 50
THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
ENDIF
Count the marks that count
- A validation tally walks the list and adds 1 only when the value is in range.
- The range test is the
ANDfrom the previous lesson, inside the loop.
Conte as notas que contam
- Uma contagem de validação percorre a lista e soma 1 apenas quando o valor está no intervalo.
- O teste de faixa é o
ANDda lição anterior, dentro do loop.
DECLARE Mark : ARRAY[1:4] OF INTEGER
DECLARE I, Count : INTEGER
Mark[1] ← 80
Mark[2] ← -1
Mark[3] ← 100
Mark[4] ← 40
Count ← 0
FOR I ← 1 TO 4
IF Mark[I] >= 0 AND Mark[I] <= 100
THEN
Count ← Count + 1
ENDIF
NEXT I
OUTPUT Count // → 3
Watch out
- The inner
IFstarts on the line afterELSE. It is not written on theELSEline. - Close the inner
ENDIFbefore the outer one. The lastENDIFbelongs to the firstIF.
Atenção
- O
IFinterno começa na linha apósELSE. Ele não é escrito na linhaELSE. - Feche o
ENDIFinterno antes do externo. O últimoENDIFpertence ao primeiroIF.
Common mistakes
- An
ENDIFin the wrong place closes the outer test and leaves the inner one open. - A mark of exactly 50 is a pass, and exactly 80 is a distinction. The tests use
>=.
Erros comuns
- Um
ENDIFno lugar errado fecha o teste externo e deixa o interno aberto. - Uma nota exatamente de 50 é aprovação, e exatamente 80 é distinção. Os testes usam
>=.
Now you try
- The first two tasks are nested decisions. The third counts with
AND. - Press Check answer to test it.
Agora você tenta
- As duas primeiras tarefas são decisões aninhadas. A terceira conta com
AND. - Pressione Check answer para testá-lo.
Read an INTEGER Mark. Output Distinction for 80 or more, otherwise Pass for 50 or more, otherwise Fail. Nest the second IF under · sob ELSE. · Leia um INTEGER Mark. Saia com Distinction para 80 ou mais, caso contrário Pass para 50 ou mais, caso contrário Fail. Aninhe o segundo IF sob ELSE.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Same three outcomes as the previous task. This input should take the inner ELSE. · Mesmos três resultados da tarefa anterior. Esta entrada deve seguir o ELSE interno.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
The array Mark holds · contém 80, -1, 100, 40. Count how many values are from 0 to · até 100 inclusive and output the count (it is 3). · O array Mark contém 80, -1, 100, 40. Conte quantos valores estão entre 0 e 100 inclusive e saia com a contagem (é 3).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.