08 — Break: stop a loop
Sometimes a loop should stop in the middle. break leaves the nearest loop
immediately and continues with the lines after it.
Steps
Create
stop.nme:
run it →set ready to True set waiting to False while ready or waiting show Still working break endThe first round runs and prints
Still working; thebreakstops the loop, so it runs exactly once.Korean uses
동안,멈춰, and끝:
run it →준비는 참 준비인 동안 작동 중이에요 말해줘 멈춰 끝break hereis the longer sentence spelling, andskipjumps straight to the next round instead of leaving the loop:
run it →set score to 0 while score is less than 10 add 1 to score if score equals 1 skip end break here endA
breakoutside a loop is an error with codeE0102; guide 11 shows how to read the message. Usebreakonly insidewhileorrepeatblocks.
Try it yourself
Stop a loop as soon as a name exists:
set name to empty
while name equals empty
ask name What is your name?
if name exists
break
end
end
run it →What you learned
break/멈춰leaves the nearest loop at once.break here/여기서 멈춰are the longer sentence spellings.skip/건너뛰어goes to the next round instead of leaving the loop.- A loop that always breaks still runs once.
breakoutside a loop is theE0102error.