Do while loop

Do-While Loop
Do-While Loop

There is also an alternate form of a while loop that’s useful in some circumstances.it is called do-while loop and it is very similar to while loop .the syntax of do-while loop is:

do
{
-
statement;
-
}while(condition);

⦁ IN this case, the operation is slightly different i.e first the statements are executed and then the condition is checked.if the condition is true the statement is executed again .if the condition is false, the statement is not executed again.

public class DoWhileExample
 { 
public static void main(String[] args)
 { 
int i=1;
 do
{
 System.out.println(i);
 i++;
 }
while(i<=10);
 } 
}
OUTPUT:
1
2
3
4
5
6
7
8
9
10
Translate »