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 trialashwathh
3,129 Pointswhile loop exercise help needed
// 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!=yes);
this code should ask for user input continuously and keep repeating it until the user press yes
// 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!=yes);
2 Answers
jb30
44,806 PointsTo compare the value of two Strings in Java, you can try something of the form response.equals("yes")
. To negate it, you could do !response.equals("yes")
.
Using !==
would work in JavaScript, but gives you an error in Java.
Jonathan Grieve
Treehouse Moderator 91,253 PointsTry changing your while
expression to the following
}while(response !== "yes");
You want to be testing for a string. `response` is a variable that holds the value of the user input. But the way you have it, Java just thinks you're testing for the value of another variable. Also the extra = for the comparison operator just ensures you're testing the exact data type and not using assigment.