Jump Statement in C
#include <stdio.h>
int getResult()
{
int result = 10;
if (result > 0) {
return result; // Return a positive value
}
}
int main()
{
for (int i = 1; i <= 5; i++) {
if (i == 3) {
continue; // Skip the remaining code for i=3
}
printf("%d ", i);
if (i == 4) {
break; // Exit the loop when i=4
}
}
printf("%d ", getResult());
int num = 5;
if (num == 5) {
goto exit; // Unconditionally jump to the 'exit'
// label
}
exit:
printf("Using goto statement.\n");
return 0;
}
Output
1 2 4 10 Using goto statement.
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