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?
// I have initialized a for you. It is in a variable named console.

2 Answers

149,602 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!