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! Answer from Patrick Bluth on teamtreehouse.com
🌐
W3Schools
w3schools.com › java › java_while_loop_do.asp
Java Do/While Loop
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... The do/while loop is a variant of the while loop. This loop will execute ...
🌐
W3Schools
w3schools.com › java › java_while_loop.asp
Java While Loop
In the next chapter, you will learn about the do while loop, which always runs the code at least once before checking the condition. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
Discussions

do while loop - Java Basic
Tanguy Muffat is having issues with: Hi guys, I would need you support. I'm stucked under challenge 2/3 where I'm being asked: "Now continually prompt the user in a do whil... More on teamtreehouse.com
🌐 teamtreehouse.com
2
November 20, 2017
What's the purpose of "do...while" loop? Can't the same result be achieved with just "while" loop?
Do while will execute at least once because the condition check to iterate through the loop is at the end. A while loop will not execute at all if the condition is not met. More on reddit.com
🌐 r/Kotlin
23
0
February 8, 2024
do while - Java do loop repeat until valid entry - Stack Overflow
I'm creating a Java project using a do-while loop to get a number from the user between 5 and 15. After this, I will create a square and triangle using the number the user entered. I'm currently... More on stackoverflow.com
🌐 stackoverflow.com
java - do-while and while comparison - Stack Overflow
I am learning about do-while vs while at the moment and would like to rewrite the above java fragment (already declared and initialized) using a while instead. More on stackoverflow.com
🌐 stackoverflow.com
People also ask

What are looping statements in Java
divLooping statements in Java are constructs that allow you to repeatedly execute a block of code They help in automating repetitive tasks by iterating through a set of instructions as long as a certain condition is metdiv
🌐
scholarhat.com
scholarhat.com › home
Loops in java - For, While, Do-While Loop in Java
What are the types of looping statements in Java
divbrJava supports three types of looping statementsbrbrdivullistrongforstrong looplilistrongwhilestrong looplilistrongdowhilestrong loopliul
🌐
scholarhat.com
scholarhat.com › home
Loops in java - For, While, Do-While Loop in Java
Can you nest loops in Java
divYes you can nest loops in Java This means placing one loop inside the body of another loop It is often used for more complex iteration scenariosdiv
🌐
scholarhat.com
scholarhat.com › home
Loops in java - For, While, Do-While Loop in Java
🌐
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)
The difference between do-while and while is that do-while evaluates its expression at the bottom of the loop instead of the top.
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-do-while-loop
Java do while loop | DigitalOcean
August 3, 2022 - Java do-while loop is used to execute a block of statements continuously until the given condition is true.
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.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-do-while-loop-with-examples
Java Do While Loop - GeeksforGeeks
Unlike for or while loops, a do-while loop checks the condition after executing the loop body, ensuring the body is executed at least once.
Published   2 weeks ago
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › java › java_do_while_loop.htm
Java - do...while Loop
Java do while loop is similar to a while loop, except that a do while loop is guaranteed to execute at least one time. The do-while loop is an exit control loop where the condition is checked after executing the loop's body.
🌐
ScholarHat
scholarhat.com › home
Loops in java - For, While, Do-While Loop in Java
It iterates over the values of i (1 and 2) and j (1 to 10), outputting the result of i * j after each iteration, using two nested do...while loops. A nested while loop and for loop in Java involves placing a while loop inside a for loop or vice versa. For each iteration of the outer loop (either while or for), the inner loop will run completely.
Published   August 30, 2025
🌐
Programiz
programiz.com › java-programming › do-while-loop
Java while and do...while Loop
If the textExpression evaluates to true, the code inside the while loop is executed. The textExpression is evaluated again. This process continues until the textExpression is false. When the textExpression evaluates to false, the loop stops. To learn more about the conditions, visit Java relational and logical operators.
🌐
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
🌐
Iqra Technology
iqratechnology.com › academy › java › java-basic › java-while-do-while-loop
Master Java Loops: While & Do-While with Examples
June 13, 2025 - A do-while loop in Java is similar to a while loop, but with one key difference: it always executes its block of code at least once before checking the loop condition.
🌐
IONOS
ionos.com › digital guide › websites › web development › java do-while loop
How to use the Java do-while loop - IONOS
January 3, 2025 - The do-while loop is used in Java to execute and repeat an in­struc­tion until a defined ter­mi­na­tion condition is fulfilled (i.e., true). Similar loops exist in most pro­gram­ming languages and are used to execute certain blocks of code multiple times.
🌐
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 - 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.
🌐
DevQA
devqa.io › java-do-and-do-while-statements
Java While and Do-While Loops with Code Examples
Let’s explore a practical example of the do-while loop: import java.util.Scanner; public class DoWhileLoopExample { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int number; do { System.out.print("Enter a number (0 to exit): "); number = scanner.nextInt(); System.out.println("You entered: " + number); } while (number != 0); System.out.println("Loop finished"); } }
🌐
BeginnersBook
beginnersbook.com › 2015 › 03 › do-while-loop-in-java-with-example
do-while loop in Java with example
class DoWhileLoopExample { public static void main(String args[]){ int i=10; do{ System.out.println(i); i--; }while(i>1); } }
🌐
ScholarHat
scholarhat.com › home
do...while Loop in Java - Flowchart & Syntax (With Examples)
September 6, 2025 - Read More: Top 50 Java Interview Questions and Answers · The do...while loop in Java is also known as Exit Control Loop. It is used byJava Developerswhen they want a block of code to be executed at least once before checking the condition.
🌐
Coding Shuttle
codingshuttle.com › java-programming-handbook › java-while-and-do-while-loop
Java while and do while loop | Coding Shuttle
April 9, 2025 - In the while loop, the condition ... In the do-while loop, the condition is checked after the loop has executed, ensuring that the loop body runs at least once, even if the condition is false initially....
Top answer
1 of 4
20

The difference between a do-while and a while is when the comparison is done. With a do-while, you'll compare at the end and hence do at least one iteration.

Equivalent code for your example

do
{ 
    i++; 
    ++j;
    System.out.println( i * j );

}
while ((i < 10) && (j*j != 25));

is equivalent to:

i++; 
++j;
System.out.println( i * j );
while ((i < 10) && (j*j != 25)) {
    i++; 
    ++j;
    System.out.println( i * j );
}

General comprehension

A do-while loop is an exit controlled loop which means that it exits at the end. A while loop is an entry controlled loop which means that the condition is tested at the beginning and as a consequence, the code inside the loop might not even be executed.

do {
    <block>
} while (<condition>);

is equivalent to:

<block>
while (<condition>) {
    <block>
};

Use case

A typical use case for a do-while is the following: you ask the user something and you want do repeat the operation while the input is not correct.

do {
   // Ask something
} while (input is not correct);

In that case, you want to ask at least once and it's usually more elegant than using a while which would require either to duplicate code, or to add an extra condition or setting an arbitrary value to force entering the loop the first time.

At the opposite, while loops are much more commons and can easily replace a do-while (not all languages have both loops).

2 of 4
3

The key difference between do-while and while, with do-while you are guaranteed at least one run of your code before the checks.

*It does not need to get anymore complicated than that.