Iteration: FOR · Iteración: FOR
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
FOR counts
- A count-controlled loop runs once for each integer from the start to the end, inclusive.
- The counter is an
INTEGER. - It is good practice to repeat the counter's name after
NEXT.
Español
BUCLES CON CONTADOR
- Un bucle controlado por contador se ejecuta una vez para cada entero desde el inicio hasta el final, inclusive.
- El contador es de tipo
INTEGER. - Es buena práctica repetir el nombre del contador después de
NEXT.
DECLARE Total : INTEGER
Total ← 0
FOR I ← 1 TO 5
Total ← Total + I
NEXT I
OUTPUT Total
Explore · Explorar
Trace the running total · Rastrear la suma acumulada
A FOR loop repeats a set number of times. Step through and watch Total grow. · Un bucle FOR se repite un número determinado de veces. Recorre paso a paso y observa cómo crece Total.
English
STEP changes the jump
STEPsets the gap between values. It can be negative.- If the start is already past the end in the step's direction, the body does not run.
Español
STEP cambia el salto
STEPestablece la distancia entre valores. Puede ser negativo.- Si el inicio ya supera al final en la dirección del paso, el cuerpo no se ejecuta.
FOR I ← 5 TO 1 STEP -2
OUTPUT I
NEXT I
English
Watch out
NEXT Imust name the counter of this loop.- The body is indented.
NEXTlines up withFOR.
Español
Atención
NEXT Idebe nombrar el contador de este bucle.- El cuerpo está indentado. Las líneas
NEXTquedan alineadas conFOR.
English
Common mistakes
1 TO 5includes both 1 and 5.- Do not change the counter yourself inside the body.
Español
Errores comunes
1 TO 5incluye tanto el 1 como el 5.- No modifique el contador usted mismo dentro del cuerpo.
English
Now you try
- Use a
FORloop to print a run of numbers.
Español
Ahora practique
- Utilice un bucle
FORpara imprimir una secuencia de números.
Use a FOR loop to output the numbers 1 to · hasta 5, one per line. · Usa un bucle FOR para imprimir los números del 1 al 5, uno por línea.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.
Output · Salida 5, 3 and · y 1, using FOR with STEP -2. · Imprime 5, 3 y 1, usando FOR con STEP -2.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.