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

what do i do

edrsdfdfsdfsdfs

Example.java
response = console.readLine("Do you understand do while loops?");
String response; 
while(true) { 
response = console.readLine("Do you understand do while loops?"); 
if (!response.equals("No")) { 
break; } }

1 Answer

Hi Mason,

First, you've declared response as being a String and get user input to a question using console.readLine(). That's the first stage of the challenge and it looks like this:

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

You've got beyond that bit and on to stage 2. Here, you need to create a do/while loop. The loop will always execute once and will continue to loop while the response equals "No". You need to amend the above response declaration to just create a variable but assign nothing to it. Then you create a do/while loop. That looks like:

String response;
do {
  // keep doing this
  response = console.readLine("Do you understand while loops?: ");
} while(condition);

The condition is a test of what the user has input. If they have entered "No", loop. Else don't ... So we need to test if response is "No". To compare strings, use the .equals() method. We can build this into the code:

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

That's stage 2 complete! Go figure out stage 3 and let me know how you get on.

I hope that helps,

Steve.