Java Java Basics Perfecting the Prototype Looping until the value passes

Tre Peterson
Tre Peterson
314 Points

Not sure why i am getting errors

Now continually prompt the user in a do while loop. The loop should continue running as long as the response is NO. Don't forget to declare response outside of the do while loop.

Example.java
// I have initialized a java.io.Console for you. It is in a variable named console.#
String response = console.readLine("Do you understand do while loops? ");
String response;
 do {
      response = console.readLine("Do you understand do while loops? ");
      isInvalidWord = (response.equalsIgnoreCase("no"));    
   if (isInvalidWord); {
   console.printf("Do you understand do while loops? ");
 }
        } 

1 Answer

Simon Coates
Simon Coates
3,092 Points
String response;
do {
    response = console.readLine("Do you understand do while loops? ");
} while(response.equals("No"));

You've defined the response variable twice and seem to have omitted the while section of the do while.