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

I really don't get this lesson

I feel like there were too many concepts put into one lesson and I simply don't understand. Can anyone give me the correct code for this please? and also with an explanation if its okay

Example.java
// 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= ("No");

1 Answer

Jordan Powell
PLUS
Jordan Powell
Courses Plus Student 5,410 Points

There are two ways to check for equality, == or the .equals() method. Remember, when you want to assign something to a variable you use one equal sign (=), but in your case, you want to check for equality in your while loop. Since you are comparing two String objects its best to use the .equals() method. Therefore, while(response.equals("No")); Sorry it was so long winded, but I figured you wanted an explanation and an example rather than just one or the other.

Hey Jordan thank you so much man! i was going crazy on why this was going wrong it turns out i just had some confusion with the "language rules" (sorry im not sure what coding term to use haha)