-1

In Java code, is there a way to have the program "skip" lines of code (NOT during debugging)? ex:

if ( userInput.equals("one") ){
   Skip to line 82
} else {
continue to next line
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724

2 Answers2

1

Just replace the condition with its logical negative, and move everything between the "next line" and line 82 (in your example) into the block.

if(!userInput.equals("one")) {
    //Next lines, up to your old line 81.
}
//Line 82.
Meindratheal
  • 158
  • 2
  • 6
0

In most languages, this Skip feature is implemented as goto.

Java made the concious decision not to include this in its language because it can enable bad code.

See

Is there a goto statement in Java?

You can always comment over lines, but you made it clear its not for debugging purposes.

Instead, use if

      if(condition){<whatever you would have had between here and 82>}.

If condition evaluates to false, the lines will be skipped.

Community
  • 1
  • 1
k_g
  • 4,333
  • 2
  • 25
  • 40