If and While Clauses

The if statement is written simply as "if" followed by a condition. The statement to be executed if the condition is true is written on the next line as a block. The condition can be put inside parentheses, if needed. If can also have an "else" part, as seen in this example.

Example: if & else
main
  a = 1
  if a == 1
    print "a is 1"     // Prints "a is 1"
  
  if (a == 1)         
    print "a is 1"     // Prints "a is 1"
  
  if a == 3
    print "a is 3"
  else
    print "a is not 3" // Prints "a is not 3"

While statement loops the given block as long as the condition remains true.

Example: While
main
  int i
  
  i = 0
  while i <= 10
    print i & " "    // Prints 0 1 2 3 4 5 6 7 8 9 10
    i++
  
  
  // Let's do that using a break statement
  i = 0
  while true
    if i > 10
      break
    print i & " "    // Prints 0 1 2 3 4 5 6 7 8 9 10
    i++