needmoreeasy EN 한국어
Learn

05 — Repeat: do something many times

★★☆☆☆ (2/5)loops
Prerequisites
04 — Update
You will end up with
a program that repeats lines, walks a list, and pauses

Computers are great at doing the same thing many times. repeat runs a line or a block again and again.

Steps

  1. Create repeat.nme:

    repeat 3 times and show Again
    
    run it →

    This prints Again three times. Korean is equally valid:

    3번 반복해서 다시 말해줘
    
    run it →
  2. When the count comes first, the rest of the line is repeated output:

    3 times Welcome to NME
    3번 안녕하세요
    
    run it →
  3. Several lines use indentation and no colon:

    repeat 3 times
        show First sentence
        둘째 문장 말해줘
    
    run it →
  4. Indentation can be optional: put end (or ) on its own line to close the block:

    repeat 3 times
    show one line
    show another line
    end
    
    run it →

    The Korean twin uses 3번 반복해 and .

  5. Instead of a fixed count you can walk through a list, the one you made in 03 — Save:

    set friends to list of Mina, Ada
    for each friend in friends
    show Hello friend!
    end
    
    run it →

    friend becomes the next value on every round. The Korean form is 친구들의 친구마다 반복해.

  6. Sometimes a loop should wait between rounds:

    repeat 3 times
    wait 1 second
    show tick
    end
    
    run it →

    Korean is 1초 기다려, and wait 3 seconds waits 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 Again prints 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 ... end closes a flat block without indentation.
  • for each friend in friends walks through a list, one value per round.
  • wait 1 second pauses right there.

This page on GitHub