by Dinesh Thakur Category: Control Structures

The do loop enables us to repeatedly execute a block of code until a boolean expression evaluates to false. It is almost identical to the while loop with the difference that here the logical expression is evaluated at the bottom of the loop rather than the top. This means that the contents of the loop will execute at least once.






}  while (expression);


The keyword do begins the do construct. This is followed by a statement or a block. Next is the keyword while, followed by the parentheses containing an expression that must evaluate to a boolean value i.e. true or false.

When a do loop is encountered, the statement or block following the do keyword is executed. When the do loop body completes, logical expression is evaluated. If it is false, execution will continue with the next statement following the do loop. If it is true, the body of the do loop will be executed again. The body will continue to execute until the expression evaluates to false.

/* Print the sequence numbers from 1 to 10 using do while loop */

class DoWhile


            public static void main(String args[] )


                        int i;




                                    System.out.print(i+ " ");





About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content

Popular Article