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

Robert Zaharia
PLUS
Robert Zaharia
Courses Plus Student 579 Points

Hi ! I can't find the mistake . I have to make a do while loop that should continue as the response is "No".

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

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do  { console.readLine("Do you understand do while loops?")}
while(response.equals("no"))

2 Answers

Hi Robert,

Your code is good. But one thing; you're asking for user input using readLine but you need to assign the result of that into response. So add response = in front of your console.readLine line.

Oh, and you may need a semi-colon right at the end of the while(response.equals("No")); and you certainly need one at the end of the line inside the while loop!. Plus "No" may need to be uppercase N too.

Sorry; I'm on my tablet and don't have a machine to check all that.

Steve.

You are very close. There are just two things wrong with this.

First, a simple syntax error. you need to end the do while loop with a semicolon, like this:

while(response.equals("no"));

Second, you need to store the result of console.readLine into the response variable, like this:

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

Here's a version that I have tested that should work:

// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do {
  response = console.readLine("Do you understand do while loops?");
} while (response.equals("No"));