while loop


Syntax:
while(condition)
{
statements;
}
It is also same as a for loop. The loop body execution is based on the Boolean condition.
The condition of the loop is check first. If the condition is found to be  a true one then, executes the loop body otherwise exit the loop. While loop is consider as an entry control loop.
Example:
while(true)
{
System.out.println("This is a never ending loop");
}

Example:

import java.io.*;
public class WhileDemo
{
public static void main(String args[]) throws IOException
{
int num;
int result = 1;
int i = 1;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a the number :");
num = Integer.parseInt(br.readLine());
System.out.println("Multiplication table of " +num+ "is given bellow ");
while(i <= 10)
{
result = num * i ;

System.out.println(num+"  *  "+i+" = "+result);
i++;
}
}
}

Output: