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

Make sure you are looping while the value stored in response is equal to No." error w/ my Do/While loop

Hello. I have no compiler errors and can't find anything online that suggests doing something than what I've already done. I get "Make sure you are looping while the value stored in response is equal to No." when I "check" my work but 0 compiler errors. I can't advance in my study. I could restructure my boolean, I suppose, but I'm now curious why THIS code won't work

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
boolean answer;

do {
  response = console.readLine("Do you understand do while loops?  ");

    if (answer = response.equalsIgnoreCase("No")); {
    console.printf("You can do better than that.  Don't have a better reaction?  /n/n");
  }
}
while (answer = response.equalsIgnoreCase("Yes")); {
  console.printf("You REALLY are getting the hang of this. \n\n");
  }

I think you simply have reversed the logic that was requested in the do-while condition; the challenge is to continually loop while the response is "No", not while the response is "Yes".

2 Answers

Raffael Dettling
Raffael Dettling
32,998 Points

You really overthinked it only do what the task says. The if statment isn´t necessary you only need the readline inside the loop.

  response = console.readLine("Do you understand do while loops?  ");

Also the while loop should run as long as response is equal to "No" afterwards just use printf as mentioned.

while (response.equals("No")); 
console.printf("Because you said %s, you passed the test!",response);

Can't thank you enough. I should have went to Oracle's website and allowed myself to see this loop in it's most stripped-down, basic state.

The challenge is asking you to loop while the response is "No". You are looping while the response is "Yes."

Can't thank you enough. I should have went to Oracle's website and allowed myself to see this loop in it's most stripped-down, basic state.