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

Hello Everybody I'm having trouble passing this stage. What should the code look like?? Any suggestions are welcome

The question asks to create a do while loop to run as long as the answer is no.

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

do{ console.printf(response);
   if(response != "No") }

1 Answer

The structure of a do while loop is like this:

do {
//some code
} while (expression)

The block inside the do while loop will always run at least once. Then the expression inside the parentheses is evaluated, and if it's true the loop runs again. So in your case it should look like this:

do {
//ask the user " Do you understand do while loops?"
//get the answer
} while (answer == "No")

The question will come up at least once. If the answer is no the condition is true, so the loop will run again, until the answer is something else than no.