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 ...
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
Java do..while loops explained with examples - Guide - The freeCodeCamp Forum
Do…While Loop The do while is similar to the while loop, but the group of statements is guranteed to run at least once before checking for a given condition. An important thing to note is ‘while’ loop is an exit control loop. while(it will not necessarily be executed), ‘do while’ ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
September 9, 2019
Why don’t we see more use of the “do...while” loop?

do while is primarily used when you want to go through one iteration of the loop body. while do implies you might not execute the body at all. I wouldn't pick one over the other based on perceived efficiency. I would base it primarily on whether you know you'll do one iteration or not.

More on reddit.com
🌐 r/learnprogramming
31
5
August 1, 2018
Do while loop
The problem is not from your loops. The problem is how you combine .nextInt() and .nextLine(). See The Scanner class and its caveats from the r/javahelp wiki More on reddit.com
🌐 r/learnjava
12
2
April 1, 2022
People also ask

When should I use a do while loop in Java?
Use it when the loop body must execute at least once, such as menu-driven programs or input validation.
🌐
wscubetech.com
wscubetech.com › resources › java › do-while-loop
Java do-while Loop: Syntax, Examples, Tips
Can I use continue in a do while loop?
Yes, continue skips the current iteration and jumps to the condition check.
🌐
wscubetech.com
wscubetech.com › resources › java › do-while-loop
Java do-while Loop: Syntax, Examples, Tips
Can I use do while loops for array traversal?
Yes, but they’re less common than for or enhanced for loops for arrays.
🌐
wscubetech.com
wscubetech.com › resources › java › do-while-loop
Java do-while Loop: Syntax, Examples, Tips
🌐
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
🌐
DataCamp
datacamp.com › doc › java › while
while Keyword in Java: Usage & Examples
The while keyword in Java is used to create a loop that executes a block of code as long as a specified condition is true.
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-while-loop-with-examples
Java while Loop - GeeksforGeeks
Control enters the while loop. The condition is tested. If true, execute the body of the loop. If false, exit the loop. After executing the body, update the loop variable. Repeat from step-2 until the condition is false. Below are the examples of Java while loop that demonstrates repeating actions and performing calculations.
Published   3 weeks ago
Find elsewhere
🌐
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
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.
🌐
Refreshjava
refreshjava.com › java › while-and-do-while-loop-in-java
while and do while loop in Java with Example - RefreshJava
do while is also a looping statement in java which allows to repeat the execution of one or more line of code as far as a condition is true. It's very similar to while loop, the only difference is that in do while loop the statements inside do while block executed first then condition expression ...
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-do-while-loop
Java do while loop | DigitalOcean
August 3, 2022 - The do-while loop in Java is similar to while loop except that the condition is checked after the statements are executed, so do while loop guarantees the loop execution at least once.
🌐
WsCube Tech
wscubetech.com › resources › java › do-while-loop
Java do-while Loop: Syntax, Examples, Tips
September 2, 2025 - Learn Java do-while loop with examples. Understand its syntax, real-life use cases, useful tips, common mistakes to avoid, and more. Read now!
🌐
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
🌐
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 - 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....
🌐
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.
🌐
iO Flood
ioflood.com › blog › while-loop-java
While Loop Java: The Basics and Beyond
February 20, 2024 - The while loop in Java is a control flow statement that allows code to be executed repeatedly based on a given condition. The condition expression must be a boolean expression. The loop executes the block of code as long as the condition is true.
🌐
freeCodeCamp
forum.freecodecamp.org › guide
Java do..while loops explained with examples - Guide - The freeCodeCamp Forum
September 9, 2019 - Do…While Loop The do while is similar to the while loop, but the group of statements is guranteed to run at least once before checking for a given condition. An important thing to note is ‘while’ loop is an exit control loop. while(it ...
🌐
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.
🌐
DataCamp
datacamp.com › doc › java › java-while-loop
Java While Loop
Java keywordsIntroduction To JavaJava File HandlingJava Language BasicsJava ArraysJava Object-Oriented Programming ... The while loop in Java is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. The loop continues to execute as long as the ...
🌐
PrepBytes
prepbytes.com › home › java › while loop program in java
While Loop Program in Java
September 22, 2023 - 5. Can I use "while" loops to iterate over arrays or collections? Yes, "while" loops can be used to iterate over arrays or collections by incrementing an index variable while the condition checks if the index is within bounds.
🌐
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.
🌐
Programiz
programiz.com › java-programming › do-while-loop
Java while and do...while Loop
Java while loop is used to run a specific code until a certain condition is met.