HaxeDoc2

(やまだぃちぅ) #1

5 trace(f);
6 f = Math.random();
7 }
8 }
9 }


This kind of while-loop is not guaranteed to evaluate the loop body expression at all: If the
condition does not hold from the start, it is never evaluated. This is different for do-while loops
(5.15).

5.15 do-while


A do-while loop starts with thedokeyword followed by the loop body expression. After that
follows thewhilekeyword, an opening parenthesis(, the condition expression and a closing
parenthesis):

1 do expression while(condition);


The condition expression has to be of typeBool.
As the syntax suggests, the loop body expression is always evaluated at least once, unlike
while (5.14) loops.

5.16 if................................................


Conditional expressions come in the form of a leadingifkeyword, a condition expression en-
closed in parentheses()and a expression to be evaluated in case the condition holds:

1 if (condition) expression;


The condition expression has to be of typeBool.
Optionally,expressionmay be followed by theelsekeyword as well as another expres-
sion to be evaluated if the condition does not hold:

1 if (condition) expression1 else expression2;


Here,expression2may consist of anotherifexpression:

1 if (condition1) expression1
2 else if(condition2) expression2
3 else expression3


If the value of anifexpression is required, e.g. forvar x = if(condition) expression1
else expression2, the typer ensures that the types ofexpression1andexpression2
unify (3.5). If noelseexpression is given, the type is inferred to beVoid.

5.17 switch.............................................


A basic switch expression starts with theswitchkeyword and the switch subject expression, as
well as the case expressions between curly braces{}. Case expressions either start with thecase
keyword and are followed by a pattern expression, or consist of thedefaultkeyword. In both
cases a colon:and an optional case body expression follows:
Free download pdf