A condition allows a specific block of code to be run only if a certain expression evaluates to a logical true value. The syntax is as follows:

var a = true
if a do print "everything's okay" 

It's simple: first the if keyword, then the expression, then do and action!

If you need more than one statement to run when the condition matches, surround them with curly braces:

var a = true
if a do
  a = false
  println "yay!"


You can also specify a block of code that would be executed if the condition isn't met with the else keyword:

var data = io:read
if data.is_i do
  print "your number is ", data
  print "not a number!"

Related pages: Visibility scopes, Convertors

Last edited Mar 17, 2011 at 9:13 AM by impworks, version 1


No comments yet.