Jump Statement in Java
/*package whatever //do not write package name here */
import java.io.*;
class GFG {
static int getResult()
{
int result = 10;
if (result > 0) {
return result; // Return a positive value
}
return 0; // Return a default value (not reached in
// this example)
}
public static void main(String[] args)
{
for (int i = 1; i <= 5; i++) {
if (i == 3) {
continue; // Skip the remaining code for i=3
}
System.out.print(i + " ");
if (i == 4) {
break; // Exit the loop when i=4
}
}
System.out.print(getResult() + " ");
// Java does not support goto
}
}
Output
1 2 4 10
Jump Statements in Programming
Jump statements in programming allow altering the normal flow of control within a program. These statements provide a way to transfer the execution to a different part of the code, facilitating conditional exits, loop control, function return, or unconditional jumps.
Table of Content
- What is a Jump Statement?
- Break Statement
- Continue Statement
- Return Statement
- Goto Statement
- Jump Statement in C
- Jump Statement in C++
- Jump Statement in Java
- Jump Statement in Python
- Jump Statement in C#
- Jump Statement in Javascript