Iteration: FOR · 반복: FOR
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version. · 이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
FOR repeats a fixed number of times
- A
FORloop counts from a start value to an end value. NEXTmarks the end of the loop body.
FOR I ← 1 TO 5
OUTPUT I // 1, 2, 3, 4, 5
NEXT I
A running total
- Start a total at 0, then add to it inside the loop.
Total ← 0
FOR I ← 1 TO 10
Total ← Total + I
NEXT I
OUTPUT Total // → 55
Explore · 탐색하기
Trace the running total · 총합 추적하기
A FOR loop repeats a set number of times. Step through and watch Total grow. · FOR 루프는 정해진 횟수만큼 반복됩니다. 단계별로 진행하며 Total이 커지는 것을 확인해 보세요.
STEP changes the count
STEPsets how much the counter changes each pass.STEP -1counts down.
FOR I ← 5 TO 1 STEP -1
OUTPUT I // 5, 4, 3, 2, 1
NEXT I
Watch out
- Use
FORwhen you know how many times to repeat; useWHILEwhen you do not. - The counter (
I) andNEXT Imust use the same name.
Common mistakes
FOR I ← 1 TO N ... NEXT Irunsntimes, including both ends.- The counter changes automatically each turn.
Now you try
- Use
FOR ... NEXT. Type<-for←. - Press Check answer to test it.
Use a FOR loop to output the numbers 1 to 5, one per line. · FOR 루프를 사용하여 숫자 1부터 5까지 줄마다 출력하십시오.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Use a FOR loop to add up 1 to 10, then output the total (it is 55). · FOR 루프를 사용하여 1부터 10까지의 합을 구한 후, 총합을 출력합니다. (총합은 55입니다.)
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Read an INTEGER N, then output N × 1, N × 2, N × 3 (one per line). For input 4, output 4, 8, 12. · INTEGER N을 읽고, 각 줄마다 N × 1, N × 2, N × 3을 출력합니다. 입력이 4일 때 출력되는 값은 순서대로 4, 8, 12입니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.