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 Censoring Words - Looping Until the Value Passes

do while loop problem

Hello Im trying to fix out this error for a quite a while. i was playing with code after one of the lessons.

I wrote something like that;

import java.io.Console;

public class whileloop{

public static void main (String[] args) { Console console = System.console();

do{
  String anyQuestions = console.readLine("Is there any Questions??");
     if (anyQuestions.equalsIgnoreCase("Yes")){
        String question = console.readLine("What is Your question? \n");
        console.printf("I dont know what '%s' means %n", question); 
     }      
    while (anyQuestions.equalsIgnoreCase("No")){
       console.printf("Lets move to the next Question %n");}
  }
}

}

And i keep receiving errors like that:

whileloop.java:16: error: while expected
}
^
whileloop.java:18: error: illegal start of expression
}
^
whileloop.java:18: error: reached end of file while parsing
}
^
whileloop.java:19: error: reached end of file while parsing
4 errors

Can some one give me some ideas what im doing wrong? Thank You

1 Answer

Irving Amador
Irving Amador
7,488 Points

You closed the if statement but you didnt close the do statement right before the while word.

          do{
                String anyQuestions = console.readLine("Is there any Questions??");
                if (anyQuestions.equalsIgnoreCase("Yes")){
                     String question = console.readLine("What is Your question? \n");
                     console.printf("I dont know what '%s' means %n", question); 
                }   // here you close the if but never close the do   
         while (anyQuestions.equalsIgnoreCase("No")){
       console.printf("Lets move to the next Question %n");}
  }
}

Just add another brakcet:

          do{
                String anyQuestions = console.readLine("Is there any Questions??");
                if (anyQuestions.equalsIgnoreCase("Yes")){
                     String question = console.readLine("What is Your question? \n");
                     console.printf("I dont know what '%s' means %n", question); 
                }  
         } while (anyQuestions.equalsIgnoreCase("No")){
       console.printf("Lets move to the next Question %n");}
  }
}