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
Post a Comment