needmoreeasy EN 한국어
Learn

06 — If: make a choice

★★☆☆☆ (2/5)conditions
Prerequisites
05 — Repeat
You will end up with
a program that runs different lines depending on a condition

Programs choose. if runs one set of lines when a condition is true, and else runs another when it is not.

Steps

  1. Create choose.nme:

    set ready to True
    if ready
        show Go
    
    run it →

    The line under if is indented. Because ready is True, it prints Go.

  2. A whole condition fits on one line with then:

    if score is greater than 10 then show You won
    
    run it →

    Korean puts the condition ending on the comparison:

    만약에 점수가 10보다 크면 성공 말해줘
    
    run it →
  3. Choices with else need a block. The flat form closes with end:

    set score to 1
    if score equals 1
    show one
    else if score equals 2
    show two
    else
    show other
    end
    
    run it →

    The Korean block uses 아니면 만약에 and 아니면 and closes with .

Try it yourself

Welcome a guest only when a name exists:

set name to Mina
if name exists
    show Welcome name
end
run it →

What you learned

  • if condition with an indented line runs it when the condition is true.
  • if ... then show ... is a one-line condition; 만약에 ...면 is Korean.
  • else / 아니면 and else if / 아니면 만약에 add other choices.

This page on GitHub