The do loop

This loop prints 1 to 12. Notice that the test is at the end.

1
2
3
4
5
6
7
8
9
10
11
12
// Uses do loop to count from 1 to 12
package numbers;
public class Numbers {
  public static void main(String[] args) {
	  int num=1; //num is given an initial value
	  do {
		  System.out.print(num+" ");
		  num++;
	  } while(num<=12);
	  System.out.println("The End");
  }//main
}//class
CODE

Output:

1 2 3 4 5 6 7 8 9 10 11 12 The End

NEXT: