05 — Repeat: do something many times
Computers are great at doing the same thing many times. repeat runs a line
or a block again and again.
Steps
Create
repeat.nme:
run it →repeat 3 times and show AgainThis prints
Againthree times. Korean is equally valid:
run it →3번 반복해서 다시 말해줘When the count comes first, the rest of the line is repeated output:
run it →3 times Welcome to NME 3번 안녕하세요Several lines use indentation and no colon:
run it →repeat 3 times show First sentence 둘째 문장 말해줘Indentation can be optional: put
end(or끝) on its own line to close the block:
run it →repeat 3 times show one line show another line endThe Korean twin uses
3번 반복해and끝.Instead of a fixed count you can walk through a list, the one you made in 03 — Save:
run it →set friends to list of Mina, Ada for each friend in friends show Hello friend! endfriendbecomes the next value on every round. The Korean form is친구들의 친구마다 반복해.Sometimes a loop should wait between rounds:
run it →repeat 3 times wait 1 second show tick endKorean is
1초 기다려, andwait 3 secondswaits longer.
Try it yourself
Repeat a greeting five times, mixing both languages:
repeat 5 times
show Hello!
반가워요! 말해줘
end
run it →What you learned
repeat 3 times and show Againprints one line three times.3 times Welcome to NME/3번 안녕하세요repeat the rest of the line.- An indented block repeats every indented line.
repeat 3 times...endcloses a flat block without indentation.for each friend in friendswalks through a list, one value per round.wait 1 secondpauses right there.