Nested decisions · Decisiones anidadas
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.
Una marca, tres resultados
- Una nota de 80 o más es una distinción, 50 o más es un aprobado, y cualquier puntuación inferior es un suspenso.
- Un
IFtiene dos caminos. La segunda decisión va dentro delELSE, como su propioIF. - Cada
IFtiene su propioENDIF. Indenta el interno para que puedas ver a quéELSEpertenece.
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.
Cuentan las notas válidas
- Un contador de validación recorre la lista y suma 1 solo cuando el valor está dentro del rango.
- La comprobación del rango es el
ANDde la lección anterior, dentro del bucle.
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.
Ten cuidado
- El
IFinterno comienza en la línea después deELSE. No se escribe en la misma línea deELSE. - Cierra el
ENDIFinterno antes que el externo. El últimoENDIFcorresponde al primerIF.
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
>=.
Errores comunes
- Un
ENDIFen el lugar equivocado cierra la prueba externa y deja abierta la interna. - Una nota exactamente de 50 es aprobada, y exactamente de 80 es distinción. Las pruebas utilizan
>=.
Now you try
- The first two tasks are nested decisions. The third counts with
AND. - Press Check answer to test it.
Ahora tú lo intentas
- Las primeras dos tareas son decisiones anidadas. La tercera cuenta usando
AND. - Pulsa Comprobar respuesta para ponerlo a prueba.
Read an INTEGER Mark. Output Distinction for 80 or more, otherwise Pass for 50 or more, otherwise Fail. Nest the second IF under · debajo de ELSE. · Leer un INTEGER Mark. Imprimir Distinction para 80 o más, de lo contrario Pass para 50 o más, de lo contrario Fail. Anidar el segundo IF bajo ELSE.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Same three outcomes as the previous task. This input should take the inner ELSE. · Mismos tres resultados que en la tarea anterior. Esta entrada debe tomar el ELSE interno.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
The array Mark holds · contiene 80, -1, 100, 40. Count how many values are from 0 to · hasta 100 inclusive and output the count (it is 3). · El array Mark contiene 80, -1, 100, 40. Contar cuántos valores están entre 0 y 100 inclusive e imprimir el conteo (es 3).
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.