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 trialGregory Delgado
Courses Plus Student 203 PointsI'm pretty stuck on do-while loops exercises. If I could please have some help that would be great!
I'm stuck on the do while loop exercises. I've watched the videos multiple times and can't get past it. I've literally followed the example from the workshop to help and still nothing. I really don't want to move on if I can't complete this exercise.
String response = console.readLine("Do you understand do while loops?");
String response;
Boolean = isInvalidWord;
do { String response = console.readLine("Do you understand do while loops?");
isInvalidWord = respone.equalsIgnoreCase("No"); }
if (isInvalidWord);
while(response.equalsIgnoreCase("No");
2 Answers
Rumyana Dimitrieva
Java Web Development Techdegree Graduate 18,632 PointsHi Gregory, in the first line of your code you already declared variable response. You don't have to do it again in line 2 and inside the loop.
The syntax of do while loop is
do {
statement(s)
} while (expression);
while the expression evaluates to true the statement(s) will be executed
in your case:
do{
response = console.readLine("Do you understand do while loops?");
}while(response.equalsIgnoreCase("No"));
Francis Stallings
2,132 PointsIn this exercise , we're trying to prompt the user to continue answering the question until they enter "yes"? This is unclear. I thought it was just a yes or no question. As a do while loop is it inherent that the code reruns until a condition is no longer in existence ( in this case its when the user enters "no"?) ? What if the user enters "dork"? Where do we store the right answer which I'm now assuming is "yes"?