Night 7: Count the stars
이미 Python 또는 의사 코드로 이날의 학습을 마쳤습니다. 두 언어 모두에서 완료한 것으로 인정됩니다. 원하면 다시 연습하세요.
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Tonight: count the stars
- It is your pet's first week! Tonight it counts the stars.
- You will learn one thing: the
FORloop.
Words for tonight
| Word | Meaning |
|---|---|
| loop | do the same thing again and again |
| repeat | do again |
| counter | the variable that counts in a loop: 1, 2, 3 … |
English
Repeat without typing again
- Five
OUTPUTlines is a lot of typing. A loop does it for you. - The lines between
FORandNEXTrun again for each number.
DECLARE Count : INTEGER
FOR Count ← 1 TO 5
OUTPUT "Star number ", Count
NEXT Count
English
How FOR counts
| You write | Count is |
|---|---|
FOR Count ← 1 TO 5 |
1 2 3 4 5 |
FOR Count ← 0 TO 2 |
0 1 2 |
FOR Count ← 2 TO 10 STEP 2 |
2 4 6 8 10 |
FORcounts up to and including the last number.NEXT Countends the loop. Use the same counter name.

English
Loop through an array
- Use the counter as the index. Each time, the loop looks at the next element.
DECLARE Snacks : ARRAY[1:3] OF STRING
DECLARE Index : INTEGER
Snacks[1] ← "apple"
Snacks[2] ← "rice"
Snacks[3] ← "fish"
FOR Index ← 1 TO 3
OUTPUT "Yum, ", Snacks[Index]
NEXT Index
English
Inside or after the loop?
- Lines between
FORandNEXTare inside the loop. They repeat. - Lines after
NEXTcome after the loop. They run once.
DECLARE Count : INTEGER
FOR Count ← 1 TO 3
OUTPUT "Zzz"
NEXT Count
OUTPUT "Good night!"
English
Week 1 is done!
- You know
OUTPUT, variables,INPUT, numbers,IF, arrays and loops. - That is the base of almost every exam algorithm.
- Finish the tasks below and your pet grows up a stage.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Your pet counts stars. Use a FOR loop to output the numbers 1 부터 5, one per line.
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Use a FOR loop to output I like and each snack in the array. The first line is I like apple.
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Read a number with INPUT Times. Output Zzz that many times, one per line. Then output Good night! once, at the end.
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Your pet saw stars on 4 nights. The array Stars 보유함 3, 5, 2 및 6. Use a FOR loop to add them all up in Total. Then output Total. The output is 16.
출력을 보려면 '실행'을 클릭하세요.