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 trialsaurav bhatt
1,444 PointsWhile loops
I know that I can't convert a string to a boolean, so how can I create a while loop for a response?
// I have initialized a java.io.Console for you. It is in a variable named conso
String response = console.readLine("Do you understand while loops? ");
while("response");
1 Answer
Ben Reynolds
35,170 PointsFor that you'll need to use an expression to compare the string to something else:
while(someString == "String value to test goes here")
You can use any of the operators here such as !=, <=, etc. So a string by itself is not a good way to check a condition, but an expression similar to the one above will evaluate to either true or false, and that can be used to control the loop.