O'Reilly logo

Real World XML by Steven Holzner

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

Java Loops: for, while, do…while

The next step after working with conditional statements is to handle loops. Like JavaScript, Java supports a for loop, a while loop, and a do...while loop.

Here's how you use a Java for loop in general, Note that the statement that makes up the body of the for loop can be a compound statement; it can be made up of several single statements enclosed in curly braces:

for (initialization_expression;
					end_conditon;
					iteration_expression) {
    statement
}

You place an expression in the initialization part of the for loop (which often initializes a variable—that is, a loop index—to 0), and then you place a test condition in the test part of the loop that is tested each time the code in the loop executes. If the test is ...

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