java - If inside a while loop, can't break out of the while loop -


i started studying java , came across problem while testing out something. might easy question, can't seem solve it. code:

    int firstj = 1;      if (firstj == 1) {         string choice = "type number between 1 , 4";         system.out.println(choice);         while (true) {              if (firstj == 1) {                 scanner third = new scanner(system.in);                 string thirdch = third.nextline();                  while (true) {                      if (thirdch.equals("1")) {                         system.out.println("show choice , accept input again ");                         system.out.println(choice);                         break;                     } else if (thirdch.equals("2")) {                         system.out.println("show choice , accept input again ");                         system.out.println(choice);                         break;                     } else if (thirdch.equals("3")) {                         system.out.println("show choice , accept input again ");                         system.out.println(choice);                         break;                     }                      else if (thirdch.equals("4")) {                         // need break loop , move on                         // "done." string                         break;                     }                      else {                         system.out.println("type number between 1 , 4");                         thirdch = third.nextline();                     }                 }              }         }     }     string done = "done";     system.out.println(done); 

i want make when type 1, 2 or 3, string telling type number again , accept user input, while when type 4 loop breaks , goes string done. grateful if me solve problem easy code, since don't know of more advanced things.

you can label loops, , use label in break statement specify loop want break out of, e.g.

outer: while (true) {   while (true) {     break outer;   } } 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -