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 trial

Java Java Basics Perfecting the Prototype Looping until the value passes

Tristan Colson
Tristan Colson
1,335 Points

not sure what im doing wrong?

i will go back though the video but i would like to see what imdoing wrong here.

Example.java
// 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"));
  {
John Bibeau
John Bibeau
1,394 Points

From 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.

Tristan Colson
Tristan Colson
1,335 Points

thank you for your help, i ended up figuring it out on my own by going over my notes very carefully.

2 Answers

Hi 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
Tristan Colson
1,335 Points

thank you for your help, i ended up figuring it out on my own by going over my notes very carefully.

Good work - well done! Give me a shout if you need assistance. :+1: :smile:

Check 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
Tristan Colson
1,335 Points

thank you for your help, i ended up figuring it out on my own by going over my notes very carefully.