O'Reilly logo

Java Quick Syntax Reference by Mikael Olsson

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

CHAPTER 8

image

Loops

There are four looping structures in Java. These are used to execute a specific code block multiple times. Just as with the conditional if statement, the curly brackets for the loops can be left out if there is only one statement in the code block.

While loop

The while loop runs through the code block only if the condition is true, and will continue looping for as long as the condition remains true. The loop below will print out the numbers 0 to 9.

int i = 0;while (i < 10) { System.out.print(i++); }

Note that the condition for the loop is only checked at the start of each iteration (loop).

Do-while loop

The do-while loop works ...

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