Home Java Beginners While Loop
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

While Loop

Advertisement
In this section you will learn how to use of while loop statement in java.

While Loop

     

Loop is the control statement of any language in which whenever you want to perform the repetitious work then you use the Loop control statement. There are mainly three types of loops. Loop repeats a statement or a process multiple times according to the specified conditions. It allows the multiple statements or process to be run for the specified time or it also follows the certain conditions. Loop makes your program readable, flexible and reliable.

While loop: While loop checks the certain condition first, if the condition is true then all the statements or processes written under the while loop are executed otherwise ignored all.

The Syntax for the while loop:
  while(condition)
  {
  statements;
   }

In this program you will see how to use the while loop statement. This program take the value of variable n and generate the table of that number which is 2.

Here is a code of program:- 

public class table{
  public static void main(String[] args){
 
 int n = 2;
  int i = 1;
  System.out.println("The table of "+n+= ");
  while(i<=10)
  {
  int t = n * i;
  System.out.println(t);
  i++;
  }
  }
}

Download this example.

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 7, 2007

Ask Questions?    Discuss: While Loop   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
burig
September 14, 2011
hello

what's the output..?
samridhi bangwal
October 22, 2011
computer applications

very nice
aaaaa
August 2, 2012
good explanation

i like the explanation
DMCA.com