How do you use goto in Java?

+1 vote
asked Sep 28, 2018 by Patrick Stock (130 points)
I don't know how goto works at all and I know I'm not supposed to use it, but it seems more convenient (If it works how I think it does) than writing more code just to go back to the beginning of the program or to a certain point in the program. It seems much easier just to "go to" that section of the code.

2 Answers

0 votes
answered Oct 1, 2018 by Shane Such (840 points)
tsk tsk that's not a good practice, don't use breaks or goto but if you do. (my tip is to look online)
0 votes
answered Apr 9, 2019 by zemiak (490 points)
there is not goto in java, you need not use it, use eg call method again in loop instead.
But tere is labels for break and continue useful in nested loops

name:              // label name
for (..
    for (...
         if (found)
             break name;

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...