Java: Conditional while loop

This entry is part 8 of 54 in the series Learn Java

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.

package javaapplication7;

public class JavaApplication7 {

    public static void main(String[] args) {
        int i = 0;
        while (i < 10) {

In the example above, i is first set to 0.  As long as i is less than 10, it will print out i.

i is incremented using i++.


Series Navigation<< Java: If else statement
Java: For loop >>