In this, part two of this ten part series on Java, Chris looks at the Java language syntax, variable declerations, truth conditions, loops and more. He finishes by wrapping everything up into a simple Java function.
Java Part 2: Syntax - The while loop (Page 6 of 8 )
The while loop is similar in action to the for loop, but different in grammar. They can always be interchanged. For example, the following while loop will iterate through the values of i until the truth test fails.
int i = 0;
while( i < 100)
// perform some action;
as with the for loop, we can construct an infinite loop. Such a loop would look like this:
while( TRUE )
// perform some action
Notice the indentation between the braces.
The do...while loop
The do...while loop is the same as a while loop, except that the body of the code will always be executed at least once.