A portion of the programme is repeatedly iterated using the Java do-while loop up until the desired condition is met. It is advised to use a do-while loop if the number of iterations is not fixed and you must run the loop at least once.
Exit control loop is the name given to Java's do-while loop. Do-while checks the condition at the end of the loop body, unlike the while loop and for loop. Because the condition is checked after the body of the loop, the Java do-while.
Flow Chart
A block of statements is constantly run until the specified condition is true using a Java do-while loop. The Java do-while loop is similar to the while loop with the exception that the condition is verified after the statements have been executed. do..while loop will ensure that statement inside loop will execute once before condition verification
Syntax
do {
// statements execute without verify condition for first iteration
}while(condition);
// Java Loop program using do.. while loop
public class whileLoop { public static void main(String[] args) { int i = 0; System.out.println("Printing the list of first 10 even numbers"); do { System.out.println(i); i = i + 2; }while(i<=10); } }
Output:
Printing the list of first 10 even numbers
0
2
4
6
8
10
// Java Loop program using do.. while loop
public class whileLoop { public static void main(String[] args) { do { System.out.println("Infinitive do...while loop"); }while (true); } }
Output:
Infinitive do...while loop
Infinitive do...while loop
Infinitive do...while loop
Infinitive do...while loop
Press Ctrl+C
Post your comment