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 trialTristan Colson
1,335 Pointsnot sure what im doing wrong?
i will go back though the video but i would like to see what imdoing wrong here.
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do {
response=console.readLine("do you understand do while loops?");
if (response.equalsIgnoreCase("no"));
{
Tristan Colson
1,335 Pointsthank you for your help, i ended up figuring it out on my own by going over my notes very carefully.
2 Answers
Steve Hunter
57,712 PointsHi Tristan,
You don't need an if
statement in there; the while
loop deals with it all for you. this would look like this:
do {
// this
}while(condition == true);
You've sussed the condition - you are testing to see if response
contains the value "No", like response.equals("No")
.
The code you are looping is the prompt to the user to enter their answer - you've got that spot on.
So, putting all that together, it looks like:
String response;
do{
response = console.readLine("Do you understand do while loops?: ");
} while(response.equals("No"));
I hope that makes sense.
Steve.
Tristan Colson
1,335 Pointsthank you for your help, i ended up figuring it out on my own by going over my notes very carefully.
Steve Hunter
57,712 PointsGood work - well done! Give me a shout if you need assistance.
Livia Galeazzi
Java Web Development Techdegree Graduate 21,083 PointsCheck again how a do while loop works. You should not use an if statement for this challenge. Also please, please, please, count your curly braces. Every opened curly brace should be closed again. Otherwise your code will not compile. Here you open two curly braces and you closed neither.
Tristan Colson
1,335 Pointsthank you for your help, i ended up figuring it out on my own by going over my notes very carefully.
John Bibeau
1,394 PointsJohn Bibeau
1,394 PointsFrom what's shown here, it looks like you need to add your while conditions and tell it what you want it to do after your if statement.