Java examples for Language Basics:for
Counter-controlled repetition with the while repetition statement.
public class Main { public static void main(String[] args) { //from w w w. j a v a 2s . c o m int counter = 1; // declare and initialize control variable while (counter <= 10) // loop-continuation condition { System.out.printf("%d ", counter); ++counter; // increment control variable } System.out.println(); } }