O'Reilly logo

haXe 2 by Benjamin Dasnois

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action—Using the continue keyword

Let's say that we want to display the number from 0 to 9 included, but not the number 8. We can use the continue keyword to do so, by directly going to the next iteration of our loop.

Let's write the following code that contains our loop, and a test done at each iteration to jump to the next iteration if needed:

for(i in 0...10)
{
if(i==8)
{
continue;
}
trace(i);
}

What just happened?

In this Time for Action, we test if i is equal to 8, if it is, we simply go to the next iteration, therefore avoiding the printing of i.

This code will display the following:

TesthaXe.hx:12: 0

TesthaXe.hx:12: 1

TesthaXe.hx:12: 2

TesthaXe.hx:12: 3

TesthaXe.hx:12: 4

TesthaXe.hx:12: 5

TesthaXe.hx:12: 6

TesthaXe.hx:12: 7 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required