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

Bummer! java.lang.RuntimeException: Too many loops attempted! Check your while condition. ()

i have given all the loops but still i am getting an error

Bummer! java.lang.RuntimeException: Too many loops attempted! Check your while condition. ()

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?");
  answer = (response.equalsIgnoreCase("yes") ||
           response.equalsIgnoreCase("no"));
  if (answer){
    console.printf("Well Done");

  }


}while(answer);

5 Answers

Thank you i understand it now

Marcus Hallenberg
Marcus Hallenberg
2,772 Points

I got stuck on the same. i think its quite idiotic cause i got a error cause i wrote "no" instead of "No"

Thomas Ferreira
Thomas Ferreira
352 Points

Almost easier to understand from a beginner than a professional. Thanks!

Tornike Shelia
Tornike Shelia
2,781 Points

I believe the right answer for this is :

   String response;

   do{

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

   }while(response == "No");

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

You don't need - boolean answer , the quiz asks you to prompt the user with the question - "Do you understand do while loops?" as long as the response is "No!" , So, step-by-step, You create the String variable - response , then create the do-while loop , in the "do" section of the loop , you have to ask the question to the user and then store the answer in the response . We do it with the console.readLine() method , and store the answer with "=" sign like this :

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

So again, - response is our variable , console.readLine() is the method which prints whatever you right inside it and returns whatever the user types , and we store that (whatever the user types ) with the equal sign - "=" ,

Next, we need the ask that same question again , and again IF the answer (whatever the user types) is - "No"

 while(response == "No");

It's that simple, "while" the "response" is double equal (which is String comparison for equality) to "No" , everything in the "do"s square brackets will run , again and again as long as the user types "No".

I hope I cleared this up , I'm a beginner myself, so I don't know much of the terms , good luck in your journey :)