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

Aidan L.
Aidan L.
1,158 Points

I don't understand this challenge question's instructions

I don't understand this challenge question's instructions.

Please Help!

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 loop?");

1 Answer

Rich Zimmerman
Rich Zimmerman
24,063 Points

So the value returned by the console.readline is stored in the response variable through each iteration through the loop.

The challenge wants you to create a do.. while loop to keep asking "Do you understand do while loop?" until you answer yes (or anything that's not "No" really..)

The trick is you have to declare the response variable outside of the loop so that you can reference it in the do while loop like so..

// here string is declared, but not defined. 
String response;
do {
  // here it's defining the response variable each time the loop runs
  response = console.readLine("Do you understand do while loop?");
  // and while the response == "No", the loop will keep on running.
} while (response == "No");