Loop statement enables program to execute the code repeatedly until the condition satisfies.
There are 3 loop statement , that are
1) For loop
2) While loop
3) Do while loop
For loop :
The code in for loop will be executed from the start value until the condition is met.
Example :
public class Forloop
{
public static void main(String[] args)
{
int i;
for (i = 1; i <=10; i++)
System.out.println("Testing Solutions");
}
}
While loop :
The code in while loop will be executed at the time when the condition is true.
Example :
public class Whileloop
{
public static void main(String[] args)
{
int i = 1;
while (i <= 5)
{
System.out.println("Welcome to Testing Solutions");
i++;
}
}
}
Do while loop :
The do while loop is like the while loop except that in do while loop, the block of code is at least executed one time although the condition is not true. The reason is that condition is checked at the bottom, not the top of the loop.
Example :
public class Dowhileloop
{
public static void main(String[] args)
{
int i = 1;
do
{
System.out.println("Testing Solutions");
i++;
} while (i <= 10);
}
}
Thanks ,
A M Balaji