Counter-controlled repetition with the while repetition statement. - Java Language Basics

Java examples for Language Basics:for

Description

Counter-controlled repetition with the while repetition statement.

Demo Code

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(); 
   } 
}

Result


Related Tutorials