Prev | Current Page 179 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

These values will very often
pertain to different objects in memory or represent flags that will keep changing until a certain value is
matched and the loop can discontinue.
The while Loop
while loops execute while a certain expression is true. Like the if statement, the supplied expression
must return a Boolean type value, though this can be forced with the use of Std.bool() .
There are typically two types of while loops: those with a condition that evaluates before any further
loop code can be executed and those with a condition that evaluates after the loop code can be executed.
The latter is known as a do while loop, as the do keyword is required:
// while loop
while ( someVar == someValue )
{
// do code
}
// do while loop
do
{
// do code
}
while ( someVar == someValue );
As with the if statement, the block braces are not required if only one line of code is present in the loop.
The differences between the while and do while loops are that, with the while loop, the loop is only
performed if the evaluated expression returns true .


Pages:
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191