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 trialmahel edu
Courses Plus Student 488 PointsDo while loop
Now continually prompt the user in a do while loop. The loop should continue running as long as the response is No. Don't forget to declare response outside of the do while loop. how to do this?
// I have initialized a java.io.Console for you. It is in a variable named console.
boolean response;
do{
cat = console.readLine("Do you understand do while loops?");
if (cat==yes){
console.printf("good");
}else(cat==no){
console.printf("bad");
}
}
2 Answers
Trent Christofferson
18,846 Pointsyou are supposed to have a do while loop but you forgot to add the while part
do {
//code here will be ran once and will keep running if the condition in the while is true
} while (boolean condition goes here)
what you need to do is if the input is "yes" set boolean var to true, you use this inside of while. if it is no boolean gets set to false
Sławomir Lasik
7,792 PointsCheck the Craig Dennis workshop on loops and especially do while loops in your case