loops - How to go back to a specific line in Java? -


i'm writing code involves if-else statement asking user if want continue. have no idea how in java. there label can use this?

this kind of i'm looking for:

--label of sort-- system.out.println("do want continue? y/n"); if (answer=='y') {     goto suchandsuch; } else {     system.out.println("goodbye!"); } 

can help?

java has no goto statement (although goto keyword among reserved words). way in java go in code using loops. when wish exit loop, use break; go loop's header, use continue.

while (true) {     // useful here...     ...     system.out.println("do want continue? y/n");     // input here.     if (answer=='y') {         continue;     } else {        system.out.println("goodbye!");        break;     } } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -