Java do-while Loop
Java do-while Loop executes at least once when the condition is checked.Do-while is used to iterate a program code several times especially when the number of iterations are not fixed.
Java do-while Loop Syntax
[
do { //code to execute } while(condition);
]
Java do-while Loop Example
[
public class DoWhile { public static void main(String args[]) { int k=1; do{ System.out.println("The number is "+k); k++; }while(k<=20); } }
]
Infinitive Java do-while Loop
Passing true in do-while loop it becomes infinitive loop.
Syntax:
[
do{ //code to be executed }while(true);
]
Infinitive Java do-while Loop Example
[
public class DoWhile { public static void main(String args[]) { int k=1; do{ System.out.println("The number is "+k); k++; }while(true); } }
]