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 trialMarina Woodson
279 PointsDo while loop syntax error. Whats wrong?
I am completely new to programming and java. I keep getting a syntax error in the line:
} while (response);
I even checked oracle.com, whats wrong with that syntax?
// I have initialized a java.io.Console for you. It is in a variable named console.
String response = ("Yes");
do {
String question = console.readLine("Do you understand do while loops?");
String question_2 = console.readLine("Do you like Java?");
} while (response);
1 Answer
Keli'i Martin
8,227 PointsThe while
is expecting a comparison inside the parentheses. Currently you just have a String in there. You need to compare that string with some literal string value. In other words:
do {
// do some stuff
} while (response == "No");
Couple of hints to get you back on track.
- You don't need to initialize the
response
value to anything, as long as it is declared outside of thedo...while
loop. - You don't need to declare a new String inside the
do...while
loop to catch theconsole.readLine()
return.
I hope this helps!