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

How do I finish challenge 2 of 3?

How do I pass challenge 2 of 3?

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.

2 Answers

Chase Marchione
Chase Marchione
155,055 Points

Hi Danielle,

The challenge's instructions are "Now continually prompt the user in a do while loop. The loop should continue running as long as the response is No. Don't forget to declare response outside of the do while loop." To break this down:

1) We want the question that we're asking the user to be contained within the do clause of the do-while loop.

2) We want to specify within the while clause of the do-while loop when we want the do clause to keep repeating (as long as response is 'No'.)

3) We'll want to declare the response variable outside of the do-while loop, because if we didn't, we'd be asking the compiler to declare it again and again (which we're not able to do syntactically--though, since response is a variable and not a constant, we can change its value as often as we like.)

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

Hope this helps!

Thanks!! it did!