“goto” equivalent in Java (kind-of)

I didn’t think that Java supported GOTO… but I revisted some documentation on control logic for java and found that you can use break label to jump backward … unfortunatly you can’t jump forward … so yea, java doesn’t support GOTO :(, but it partially does, heres an example from the Sun docs:

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;
    }
  }
}

I remember looking for a goto tag and it seemed I overlooked a post in this forum.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s