Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Conditionals

if / else / endif blocks execute based on a comparison between two values.

if age >= 18
    println 'Adult'
else
    println 'Minor'
endif
  • Every if must be closed with endif.
  • else is optional.
  • The condition uses one of the comparison operators: ==, !=, >, <, >=, <=.

Nesting

if/endif blocks nest freely — there’s no elseif, so a chain of conditions is written as nested if/else blocks:

if mode == 1
    println 'Mode one'
else
    if mode == 2
        println 'Mode two'
    else
        println 'Unknown mode'
    endif
endif

This is exactly the pattern used in the Temperature Converter example. See also FizzBuzz, which nests three levels deep to check divisibility by 15, 3, and 5.