Prev | Current Page 180 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

However, with the do while loop, the loop code
will occur at least once regardless of the expression, but will only repeat if the evaluated expression
returns true .
class WhileLoops
{
public static function main()
{
var myInt : Int = 0;
// will print to screen ten times
while ( myInt < 10 )
trace( ???displayed ??? + ( ++myInt ) + ??? times??? );
// will skip as myInt == 10
while ( myInt < 10 )
trace( ???displayed ??? + ( ++myInt ) + ??? times??? );
Chapter 4: Controlling the Flow of Information
81
// will display once as myInt will be bigger than 0
// though this is not evaluated until after one iteration
do
trace( ???displayed ??? + ( 10 - --myInt ) + ??? times??? )
while ( myInt < 0 );
}
}
As you can see in the example, the line executed in the do while loop does not end with a semicolon ( ; ).
Like if statements, a do while loop doesn ??™ t require a single line of code to end with a semicolon. In fact,
the compiler is insistent that one does not exist. You will still need to apply them to blocks of code,
however.


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