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
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
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.
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.