Difference between while and do while loop in java

By | April 22, 2019

Difference between while and do while loop in java:

while loop do while loop
Checks the condition before executing the statement. It first executes the statement and then checks the condition.
Entry controlled loop. Exit controlled loop.
Condition comes before the body. Condition comes after the body.
Statement(s) are executed at least once.
Example:

int i=10;
while(i<5){
System.out.println(“i value is: “+i);
}

Output: No output.

Example:

int j=10;
do{
System.out.println(“j value is: “+j);
}while(j<5);

Output: j value is: 10

 

Leave a Reply

Your email address will not be published. Required fields are marked *