Iteration: WHILE and REPEAT · Iteración: WHILE y REPEAT
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · Esta página necesita un navegador reciente (con soporte para SharedArrayBuffer). Por favor, actualiza Chrome, Edge, Firefox o Safari a la última versión.
English
WHILE tests first
- A pre-condition loop tests the condition, then maybe runs the body.
- If the condition is already
FALSE, the body never runs. - The block ends at
ENDWHILE.
Español
Prueba de WHILE primero
- Un bucle de precondición prueba la condición, y luego puede ejecutar el cuerpo.
- Si la condición ya es
FALSE, el cuerpo nunca se ejecuta. - El bloque termina en
ENDWHILE.
DECLARE N : INTEGER
N ← 3
WHILE N > 0
OUTPUT N
N ← N - 1
ENDWHILE
English
REPEAT runs, then tests
- A post-condition loop runs the body, then tests.
- The body runs at least once.
- The loop stops when the condition becomes
TRUE.
Español
REPEAT ejecuta, luego prueba
- Un bucle de postcondición ejecuta el cuerpo, y luego prueba.
- El cuerpo se ejecuta al menos una vez.
- El bucle se detiene cuando la condición se vuelve
TRUE.
DECLARE N : INTEGER
N ← 0
REPEAT
N ← N + 1
OUTPUT N
UNTIL N = 3
English
Watch out
WHILEstops onFALSE.REPEATstops onTRUE. They are opposite tests.- Something inside a
WHILEmust change the condition, or the loop never ends.
Español
Cuidado
WHILEse detiene enFALSE.REPEATse detiene enTRUE. Son pruebas opuestas.- Algo dentro de un
WHILEdebe cambiar la condición, o el bucle nunca terminará.
English
Common mistakes
ENDWHILEcloses aWHILE.UNTILcloses aREPEAT.- A
REPEATthat should stop at 3 must updateNbefore the test.
Español
Errores comunes
ENDWHILEcierra unWHILE.UNTILcierra unREPEAT.- Un
REPEATque debe detenerse en 3 debe actualizarNantes de la prueba.
English
Now you try
- Write one
WHILEand oneREPEAT.
Español
Ahora tú lo intentas
- Escribe uno
WHILEy unoREPEAT.
Set · Conjunto N to · hasta 3. While N is greater than 0, output N and then subtract 1. · Asigne N el valor de 3. Mientras N sea mayor que 0, muestre N y luego resta 1.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Use REPEAT … UNTIL to output 1, 2 and · y 3. · Utilice REPEAT … UNTIL para mostrar 1, 2 y 3.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.