Scriptol/If Control Structure

If Control StructureEdit

Common syntaxEdit

For a conditional process, the statement is a "if" keyword, followed by a boolean expression, a list of statements to execute or no, depending of the condition, and the "/if" keyword.

If x = 5
  print "equal"
/if 


Introducing an alternative by the "else" keyword: when the condition is false, another list of statements may be processed.

If x = 5
  print "equal"
else
  print "not equal"
/if 


One-line structureEdit

When the body of the structure is just one statement, and not another structure, the syntax may be shortened to only a single line.

If x = 5 print x 


If the statement is not a command as "print", "break", "continue" etc..., the "let" keyword is required.

If x = 5 let y + 1 


Composite ifEdit

The structure may be extended into a more powerful construct that is both an "if" and a "switch case" structure, even more advanced than the C counterpart since you can test any type of variable.

if x 
  = 5: print "equal"
  > 5: print "more"
else 
  print "less"
/if