Java Java Basics Perfecting the Prototype Looping until the value passes

Sarah Hermansen
Sarah Hermansen
251 Points

Compiler error

I'm a little confused -- could someone help me point out the error?

Example.java
String response;
do {
  response = console.readLine("Do you understand while loops?");
  if (response.equalsIsIgnoreCase("no")) {
  }
  } while(noun.equalsIgnoreCase("no")) {
}
// I keep getting a compiler error, please help!!!

1 Answer

joelearner
joelearner
48,725 Points

Hi Sarah!

It looks like things just got a little jumbled. Not a problem! This is not too bad to fix.

One thing is to eliminate many of the curly braces. The only curly braces you need here are for the "do" part of the loop. You will not need them for the "while" part of the loop.

Also, the beginning of an if statement found its way in but this challenge does not need a conditional. The do while loop will pass the requirement just fine.

Then we'll keep the while condition simple and just require the response to be "No" (like the way it is written in the question).

When you're finished, your code should look something like this:

String response;

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

Cheers!