The example below demonstrates a while loop.

// While loop

public class WhileLoop {
    public static void main(String [] args) {
	int x = 1;
	int y = 2;
	while (x < 100) {
	    x = x + y;
	    y = y * 2;
	    System.out.println("x = " + x + "  y = " + y);
	}
	System.out.println("After the loop: x = " + x + "  y = " + y);
    }
}

This is an example from CSci 2101 course.