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

Haydn Hurst
Haydn Hurst
2,358 Points

I am stuck on step two of this task; I cannot figure out how to make the do/while loop work.

The part of the loop I can't get is the while part. It gives me an error about not getting strings to booleans, but I don't know how to convert it properly, or even if that is the correct way to go.

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

You should be using a comparison operator instead of the assignment operator:

while (response == "No")

Note: I also changed the case of the N in no since that is what the task asks for.

Haydn Hurst
Haydn Hurst
2,358 Points

I don't know why I didn't think of that! Thank you so much!