Statements
Statements are fragments of the program that are executed in sequence, usually contains a condition expression.
Attention
= operator in condition expression represents relational operation “equals”, equavlant to ==.
Selection statements
A selection statement chooses between one of several control flows.
If statement
If statement conditionally executes another statement.
If foo = 3.14 Then
Print("true statement")
ElseIf foo = 1.14 Then
Print("elseif statement")
Else
Print("false statement")
EndIf
foo = 3.14 is a condition expression, when the expression is not 0, the true statement will be executed. Condition expression must returns an Integer value. Then keyword is optional.
You can add optional ElseIf and Else parts for different conditions. These statements can execute one at the same time. Note that Else can only be used once.
You can also fold the if statement into a single line. Note that no EndIf required.
If foo = 3.14 Then Print("true statement") Else Print("false statement")
Iteration statements
An iteration statement repeatedly executes some code.
While statement
While statement conditionally looping executes another statement.
Local i% = 0
While i < 10 Then
Print(i)
i = i + 1
Wend
i < 10 is a condition expression, when the expression is not 0, the while statement will be executed. Condition expression must returns an Integer value. Then keyword is optional.
You can also fold the while statement into a single line. Note that no Wend required.
While i < 10 Then Print(i) : i = i + 1