Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Java Java Basics Perfecting the Prototype Looping until the value passes

Berkay Gökkaya
Berkay Gökkaya
2,316 Points

Help doing the loop

I dont know how to do the loop correctly.

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response= console.readLine ("Do you understand do while loops?");
do {
    while(response.equals("No");
        }

2 Answers

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 32,258 Points

Hi Berkay. Simply moving:

response= console.readLine("Do you understand do while loops?");

inside the loop should fix it.

You do still need to declare response outside the loop

Mark Sebeck
MOD
Mark Sebeck
Treehouse Moderator 32,258 Points

Hi Berkay. You have the basic structure of the Do While loop but you have a couple of Syntax errors. First on the while loop you open Parentesis twice but only close once. So add another ) to the end of your while.

while(response.equals("No"));

Also the curly brackets should close before the while statement not after.

}
while(response.equals("No"));

Now we need to think about what should go inside the loop. Each time you are going to check if the response = "No". If it equals "No" you loop again. If it doesn't equal No then you exit. So you should probably ask the user each time if they understand loops. Hope this helps and post back if you are still stuck

Berkay Gökkaya
Berkay Gökkaya
2,316 Points

Hey Mark,

thank you very much already. But I still need help. How do I continue from here on:

String response= console.readLine("Do you understand do while loops?");
do {
} while(response.equals("No"));