Do While Loop In Java
The do-while is similar to the while loop. In do-while loop, the condition is evaluated after the execution of statements with in the do block at least once.
Syntax:
do { //statement(s); } while(condition);
Sample Program:
package ClassThreeControlFlowStatements; public class DoWhileLoop { public static void main(String[] args) { int i=10; do{ System.out.println(i); i--; } while(i>1); } }
Must Read: Java Tutorial
Hi Sir,
I am very happy, because of your valuable online materials. I just need to indicate you that, the syntax and sample program for the while and do-while loops are interchanged. I hope you will see this comment and consider as an important to change. Please do as soon as possible. Then only the visitors cannot get confused while referring this.
Thank you.
Thanks Karthik.