🌐
W3Schools
w3schools.com › java › java_while_loop_do.asp
Java Do/While Loop
The do/while loop is different: it will always run the code block at least once, even if the condition is false from the start. In the example below, the variable i starts at 10, so i < 5 is false immediately.
🌐
Tutorialspoint
tutorialspoint.com › java › java_do_while_loop.htm
Java - do...while Loop
The following diagram shows the flow diagram (execution process) of a do while loop in Java - In this example, we're showing the use of a while loop to print numbers starting from 10 to 19.
🌐
IONOS
ionos.com › digital guide › websites › web development › java do-while loop
How to use the Java do-while loop - IONOS
January 3, 2025 - This condition is always expressed as a Boolean ex­pres­sion, meaning, within the program’s logic, it evaluates to either true or false. A common and useful example of such an ex­pres­sion is a counter variable, which allows you to determine ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-do-while-loop-with-examples
Java Do While Loop - GeeksforGeeks
The loop continues until the condition c <= 5 becomes false, after which the loop terminates. ... Note: The test_expression in a do-while loop must evaluate to a boolean value; otherwise, a compile-time error occurs.
Published   3 weeks ago
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › while.html
The while and do-while Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
Therefore, the statements within the do block are always executed at least once, as shown in the following DoWhileDemo program: class DoWhileDemo { public static void main(String[] args){ int count = 1; do { System.out.println("Count is: " + count); count++; } while (count < 11); } }
🌐
W3Schools
w3schools.com › java › java_while_loop.asp
Java While Loop
How Tos Add Two Numbers Swap Two ... Loop Loop Through an Enum ... assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String ...
🌐
ScholarHat
scholarhat.com › home
do...while Loop in Java - Flowchart & Syntax (With Examples)
September 6, 2025 - The update expression in the do...while is the one that updates the variable of the loop. It may increment or decrement depending on the specifications. The update expression makes sure that at some point the test expression will evaluate to 'False' and the loop will terminate eventually. Consider this example below in Java Online Editor to identify both the expressions of the do...while loop.
🌐
GeeksforGeeks
geeksforgeeks.org › java › loops-in-java
Java Loops - GeeksforGeeks
The do-while loop ensures that the code block executes at least once before checking the condition. Example: The below Java program demonstrates a do-while loop that prints numbers from 0 to 10 in a single line.
Published   August 10, 2025
🌐
Programiz
programiz.com › java-programming › do-while-loop
Java while and do...while Loop
The do...while loop is similar to while loop. However, the body of do...while loop is executed once before the test expression is checked. For example,
Find elsewhere
🌐
BeginnersBook
beginnersbook.com › 2015 › 03 › do-while-loop-in-java-with-example
do-while loop in Java with example
Here we have an integer array and we are iterating the array and displaying each element using do-while loop.
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-do-while-loop
Java do while loop | DigitalOcean
August 3, 2022 - Here is a simple java do-while loop example to print numbers from 5 to 10.
🌐
Javatpoint
javatpoint.com › java-do-while-loop
Java Do While Loop - javatpoint
Java do while loop, java do while loop examples, nested do while loop in java, difference between java while loop and do while loop with concepts and examples.
🌐
Upgrad
upgrad.com › home › blog › software development › do while loop in java: syntax, examples, and practical applications
Do-While Loop in Java: Examples, Applications & Tips 2025
September 10, 2025 - The loop continues executing as long as i is less than or equal to the specified limit num. This example shows that do while syntax Java loops are well-suited for tasks requiring cumulative calculations that must run at least once.
Top answer
1 of 2
3
Hi Tanguy, I have seen this problem come up a lot. You do not actually need a boolean to run your do while loop, and you can simplify it a lot by having the loop depend on the response directly. java // I have initialized a java.io.Console for you. It is in a variable named console. String response; do{ response = console.readLine("Do you understand do while loops?"); }while(response.equalsIgnoreCase("no")); You may also include your print statement that you included using if(response.equalsIgnoreCase("no")). HOWEVER, with all that being said, what you did actually works fine! You just made a typo in your code. You wrote invalidReponse not invalidReSponse, as declared outside your loop. You can see these errors easily if you check the compiler error (You would see a symbol not found error point to that variable) Hope that helps!
2 of 2
0
I think i'm very unfamiliar with this kind of Java syntax. Using the console.printf() instead of System.out.println() and console.readLine() instead of scanner.nextLine(). I still don't understand why Tanguy Muffat's program works after fixing the syntax error. I don't understand how having the [while(response.equalsIgnoreCase("no"));] at the bottom works. Normally i would expect it to look more like : do{ while(response.equalsIgnoreCase("no")) { console.printf("Sorry you cannot continue the training. Train harder to understand the concept. \n"); }} I would think that a while condition with no brackets under it and nothing inside of it wouldn't work. In Tanguy Muffat's program it looks like the while loop is completely outside of the do loop.
🌐
Tutorial Gateway
tutorialgateway.org › java-do-while-loop
Java Do While Loop
March 25, 2025 - Third Iteration Within the Second Iteration of Java Do While Loop, the values of both changed as Number = 2 and sum = 7 sum = 7 + 2 ==> 9 · After the decrement, the condition (1 > 0) is True · Fourth Iteration After the third Iteration, Number = 1 and sum = 9 sum = 9 + 1 ==> 10 · Next, the number will be decremented by 1 (number –). Next, the condition inside the while is True or Not. Here, 0 > 0 is False. The last System.out.format statement in the example will print the number of digits in the given number as output.
🌐
DevQA
devqa.io › java-do-and-do-while-statements
Java While and Do-While Loops with Code Examples
In this example, the loop asks the user to enter a number repeatedly until they input 0. Even if the user inputs 0 on the first try, the loop’s code block will still execute once before checking the condition.
🌐
SitePoint
sitepoint.com › blog › java › java’s while and do-while loops in five minutes
Java's While and Do-While Loops in Five Minutes — SitePoint
November 5, 2024 - The primary difference between a while loop and a do-while loop in Java lies in their execution. A while loop first checks the condition before executing the loop body. If the condition is false at the start, the loop body will not execute even once. On the other hand, a do-while loop executes the loop body first and then checks the condition.
🌐
Coding Shuttle
codingshuttle.com › home › handbooks › java programming handbook › java while and do while loop
Java while and do while loop | Coding Shuttle
April 9, 2025 - This blog explains Java's while and do-while loops with clear syntax, real-world examples, and key differences between the two. Learn how each loop works, when to use them, and how they behave in infinite loop scenarios.
🌐
Jenkov
jenkov.com › tutorials › java › while.html
Java while Loops
May 9, 2024 - If the current String in the strings array does start with the letter j, then the next Java statement after the if statement is executed, and the variable wordsStartingWithJ is incremented by 1. The continue command also works inside do while loops. Here is a do while version of the previous example: