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 trialtrina joy
6,525 PointsDo While loop - I still have syntax errors..
JavaTester.java:133: error: while expected } ^ JavaTester.java:137: error: illegal start of expression taskNumber = 1; ^ JavaTester.java:137: error: ')' expected taskNumber = 1; ^ 3 errors
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean No;
do {
response = console.readLine("Do you understand do while loops?");
false = (response.equalsIgnoreCase("No"));
if (response == No){
console.printf("the answer is no");
}
while (true);
}
3 Answers
Steven Stanton
59,998 PointsThe while needs to come after the final curly bracket - at the moment it is inside the the do code block.
Grigorij Schleifer
10,365 PointsHi trina,
here is a schematic view of a do/while loop
do{
//here comes your code you want to be executed at least once
//this is also the loop part
} while(//here comes your condition, it can be true or false, depending on what you are supposed to do, if its true - the loop will be executed);
The challenge should look like this:
String response; //in this String variable the user input will be stored/assignet
do {
response = console.readLine("Do you understand do while loops?"); //the answer of the user will be stored/assigned from console into "response"
} while(response.equalsIgnoreCase("no")); //while the answer is no or No, the condition is true and the loop goes on, if the condition is false (Yes) the loop stops
I hope it helps ...
Grigorij
Grigorij Schleifer
10,365 PointsYou also can do:
do {
response = console.readLine("Do you understand do while loops?");
} while(!response.equalsIgnoreCase("yes"));//while the response is not yes or Yes do the loop. If response is yes/Yes the while condition is false and the loop stops
Grigorij Schleifer
10,365 PointsHey trina,
how is your challenge-solving going?
Grigorij