Conditionals
if / elif / else / endif blocks execute based on a comparison between two values.
if age >= 18
println 'Adult'
else
println 'Minor'
endif
- Every
ifmust be closed withendif. elseandelifare optional.- The condition uses one of the comparison operators:
==,!=,>,<,>=,<=.
Chaining Conditions
Use elif (else-if) to chain multiple conditions without nesting:
if mode == 1
println 'Mode one'
elif mode == 2
println 'Mode two'
else
println 'Unknown mode'
endif
You can chain as many elif blocks as needed:
if number % 15 == 0
println 'Divisible by 15'
elif number % 3 == 0
println 'Divisible by 3'
elif number % 5 == 0
println 'Divisible by 5'
else
println 'Not divisible by 3 or 5'
endif
Inline Expressions in Conditions
Conditions can include arithmetic and other expressions directly:
number = 15
if number % 15 == 0
println 'Divisible by 15'
elif number % 3 == 0
println 'Divisible by 3'
endif
See also Loops, FizzBuzz, and Temperature Converter for examples of conditionals in action.