07 — While: keep going
repeat runs a fixed number of times. while keeps running as long as a
condition stays true — and stops when it becomes false.
Steps
Create
count.nme:
run it →set score to 0 while score is less than 3 show score add 1 to score endThe block closes with
end, so indentation is optional. The program prints0,1,2and stops whenscorereaches 3.Korean uses
동안and끝:
run it →점수는 0 점수가 3보다 작은 동안 점수 보여줘 점수에 1 더해 끝English and Korean can mix in one condition. The Korean ending
동안follows the subject:
run it →점수는 0 while 점수가 3보다 작을 동안 show 점수 add 1 to 점수 endA spoken one-line loop puts the ending on the subject:
run it →준비는 참 준비하는동안 성공 말해줘 준비는 거짓The last line makes the condition false, so the loop stops after one round. Without it the loop never ends.
Try it yourself
Loop while a name is missing, asking until one appears:
set name to empty
while name equals empty
ask name What is your name?
end
run it →What you learned
while condition...endloops while the condition is true.동안 조건...끝is the Korean spelling.- The loop must change its condition, or it never stops.
- Spoken Korean can end the loop on the subject:
준비하는동안.