While Loop

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

While Loop

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

While Loop

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.