- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java do-while loop example
A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.
Syntax
Following is the syntax of a do...while loop −
do { // Statements }while(Boolean_expression);
Notice that the Boolean expression appears at the end of the loop, so the statements in the loop execute once before the Boolean is tested.
If the Boolean expression is true, the control jumps back up to do statement, and the statements in the loop execute again. This process repeats until the Boolean expression is false.
Flow Diagram
Example
public class Test { public static void main(String args[]) { int x = 10; do { System.out.print("value of x : " + x ); x++; System.out.print("
"); }while( x < 20 ); } }
Output
value of x : 10 value of x : 11 value of x : 12 value of x : 13 value of x : 14 value of x : 15 value of x : 16 value of x : 17 value of x : 18 value of x : 19
- Related Articles
- Java infinite do-while loop
- What are the differences between while loop and do-while loop in Java?
- How to use ‘do while loop’ in Java?
- do…while loop vs. while loop in C/C++
- Java while loop
- Difference Between while and do-while Loop
- Do-while loop in Arduino
- The do…while loop in Javascript
- Infinite while loop in Java
- Java while loop with Examples
- How to use C# do while loop?
- What is do...while loop statement in JavaScript?
- How to use ‘while loop’ in Java?
- Why there is not do...while loop in Python?
- How to emulate a do-while loop in Python?

Advertisements