Skip to content

Latest commit

 

History

History
54 lines (47 loc) · 4.92 KB

conditions.md

File metadata and controls

54 lines (47 loc) · 4.92 KB

Documentation

Conditions

if [relation] [statement] end

if [relation] [statement]
else [statement] end

if [relation]
  [statement]
end

if [relation]
  [statement]
else
  [statement]
end

An if, if its condition is truthy, executes the following statements until end is encountered, otherwise it executes the statements that follow the next end or the next else until end is encountered. It is used where code needs to be executed only if a given condition is true. An if or else statement can execute a single statement and fit in a single line:

@fine = true
if @fine print "All is fine!" end

// Or

if not @fine print "Some error occurred"
else print "All is fine!" end

or can also conditionally execute a group of statements:

# Condition block

if 1 == 1
  print "All is fine!"
  print "Equality works"
else
  print "Some error occurred!"
  print "Equality does not work"
end