Iteration: FOR · Iteração: FOR
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · Esta página precisa de um navegador recente (com suporte a SharedArrayBuffer). Por favor, atualize Chrome, Edge, Firefox ou Safari para a versão mais recente.
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.
Português
FOR conta
- Um loop controlado por contador executa uma vez para cada inteiro do início ao final, inclusive.
- O contador é um
INTEGER. - É boa prática repetir o nome do contador após
NEXT.
DECLARE Total : INTEGER
Total ← 0
FOR I ← 1 TO 5
Total ← Total + I
NEXT I
OUTPUT Total
Explore · Explorar
Trace the running total · Rastreie o total acumulado
A FOR loop repeats a set number of times. Step through and watch Total grow. · Um loop FOR repete um número definido de vezes. Passe passo a passo e observe Total crescer.
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.
Português
STEP muda o salto
STEPdefine o intervalo entre valores. Pode ser negativo.- Se o início já estiver além do final na direção do passo, o corpo não executa.
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.
Português
Atenção
NEXT Ideve nomear o contador deste loop específico.- O corpo está recuado.
NEXTalinha-se comFOR.
English
Common mistakes
1 TO 5includes both 1 and 5.- Do not change the counter yourself inside the body.
Português
Erros comuns
1 TO 5inclui tanto 1 quanto 5.- Não altere o contador manualmente dentro do corpo.
English
Now you try
- Use a
FORloop to print a run of numbers.
Português
Agora você tenta
- Use um loop
FORpara imprimir uma sequência de números.
Use a FOR loop to output the numbers 1 to · até 5, one per line. · Use um loop FOR para imprimir os números 1 a 5, um por linha.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Output · Saída 5, 3 and · e 1, using FOR with STEP -2. · Imprima 5, 3 e 1, usando FOR com STEP -2.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.