while (boolean __condition) { }
if (boolean __condition) { } else { }
Description
Is used for the control structures. You can also take a look at foreach().
if, else
Executes the code block following the statement if condition evaluates to true. Executes the code in the (optional) else
statement otherwise. The code following one of the statements has to be enclosed in curly brackets, except for else
when else if
is used together.
while
Same as above, except that after execution the statement is always evaluated again and the code block re-executed accordingly. There is no else
after a while
loop.
Example
Executing the following code:
use System; var testvalue = 3; if (testvalue > 2) { System.print("Testvalue is larger than 2."); } else { System.print("Testvalue is not larger than 2."); }
will print:
Testvalue is larger than 2.
The next example is a possible use of a while
loop.
while(i<file_count) { processNextFile(); i += 1; }
More than two cases
You can use multiple if
clauses in succession:
if ( ... ) { ... } else if ( ... ) { ... } else if ( ... ) { ... } else { ... }
The combination else if
makes sure that never more than one block is executed, and you don't have to nest consecutive if
blocks, which is important.