Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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 37,555 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 37,555 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"));