Iteration: FOR · Itération : FOR
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · Cette page nécessite un navigateur récent (avec support SharedArrayBuffer). Veuillez mettre à jour Chrome, Edge, Firefox ou Safari vers la dernière version.
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.
Français
FOR compte
- Une boucle contrôlée par compteur s'exécute une fois pour chaque entier du début à la fin, inclus.
- Le compteur est un
INTEGER. - C'est une bonne pratique de répéter le nom du compteur après
NEXT.
DECLARE Total : INTEGER
Total ← 0
FOR I ← 1 TO 5
Total ← Total + I
NEXT I
OUTPUT Total
Explore · Explorer
Trace the running total · Tracez le total accumulé
A FOR loop repeats a set number of times. Step through and watch Total grow. · Une boucle FOR répète un nombre défini de fois. Passez étape par étape et observez Total croître.
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.
Français
STEP modifie le pas
STEPdéfinit l'écart entre les valeurs. Il peut être négatif.- Si le début est déjà passé la fin dans la direction du pas, le corps ne s'exécute pas.
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.
Français
Attention
NEXT Idoit nommer le compteur de cette boucle.- Le corps est indenté.
NEXTs'aligne avecFOR.
English
Common mistakes
1 TO 5includes both 1 and 5.- Do not change the counter yourself inside the body.
Français
Erreurs courantes
1 TO 5inclut à la fois 1 et 5.- Ne modifiez pas le compteur vous-même à l'intérieur du corps.
English
Now you try
- Use a
FORloop to print a run of numbers.
Français
À vous maintenant
- Utilisez une boucle
FORpour imprimer une suite de nombres.
Use a FOR loop to output the numbers 1 to · à 5, one per line. · Utilisez une boucle FOR pour afficher les nombres 1 à 5, un par ligne.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.
Output · Sortie 5, 3 and · et 1, using FOR with STEP -2. · Affichez 5, 3 et 1, en utilisant FOR avec STEP -2.
Click Run to see the output here. · Cliquez sur Exécuter pour voir le résultat ici.