Actions
IF in Scol¶
if <condition> then <instructions> else <instructions>
else is imperative.
More complicated :
if (((condition1) && (condition2)) || (condition3)) then ( instructions ) else if (condition4) then ( instructions ) else ( instructions )
For a simple condition, like x < 5, the () is not imperative but recommended. For others cases, ( ) are needed.
Be careful, if <condition> then <instructions> else <instructions> is one instruction ! There is only a semicolon at the end of the last instruction of else block.
Example :
fun main ()= _showconsole; srand time; let ((rand&255)*100)>>8 -> x in // randomized value if (x < 10) then _fooS "x is small" // no semicolon ! else if (x > 90) then _fooS "x is big" // no semicolon ! else _fooS "x is medium"; // semicolon ! 0;;
other example :
fun main ()= _showconsole; srand time; let ((rand&255)*100)>>8 -> x in // randomized value let mod x 2 -> m in // modulo x by 2 if m == 0 then ( _fooS strcat "x = " itoa x; _fooS strcat "x is even"; ) // no semicolon ! else ( _fooS strcat "x = " itoa x; _fooS strcat "x is uneven"; ); // semicolon ! 0;;
License : CC-BY-SA-2.0
Tutorial by iri
Updated by /
Updated by iri about 12 years ago · 1 revisions