Equivalent to GOTO in Java

2

Well folks, I'd like to know how a goto in java does? or some way to get back to a certain point in the code, people say that it's dangerous to use this type of command in java ... why?

    
asked by anonymous 26.03.2017 / 06:11

1 answer

5

There is no direct equivalent to the GOTO concept in Java (1) . There are some options that allow you to do some of the things similar to the classic GOTO. According to this answer in SOen , one option is to use BREAK . Here's how it would look:

search:
for (i = 0; i < arrayOfInts.length; i++) {
  for (j = 0; j < arrayOfInts[i].length; j++) {
    if (arrayOfInts[i][j] == searchfor) {
      foundIt = true;
      break search;
    }
  }
}
    
26.03.2017 / 06:34