While loop in Java
In while loop
In while loop
- Initialization is done
- Then condition is check
- If condition is true then body of loop is executed
Format for while loop
While (condition)
{
Body of loop
}
In while loop condition is check first
If it is true then body of loop is executed
After this execution condition is again check
Body of loop is executed till the condition in
While loop is false
While (condition)
{
Body of loop
}
In while loop condition is check first
If it is true then body of loop is executed
After this execution condition is again check
Body of loop is executed till the condition in
While loop is false
Example: Write the program to print the number of table
class Table
{
public static void main(String[] args)
{
int num=2,table=0,j=1;
while(j<11)
{
table=num*j;
System.out.println(+table);
j++;
}
}
}
{
public static void main(String[] args)
{
int num=2,table=0,j=1;
while(j<11)
{
table=num*j;
System.out.println(+table);
j++;
}
}
}
No comments:
Post a Comment