Jump Statements in C++ – Complete Tutorial
Last Updated on: 8th Dec 2025 17:51:15 PM
In programming, execution normally flows line by line from top to bottom.
However, in real applications, sometimes we need to suddenly change the flow of execution—skip some statements, exit a loop early, return from a function, or jump to another part of the program.
These situations are handled using Jump Statements.
Jump statements allow the program control to transfer immediately from one part of the code to another without following the normal sequential flow.
They are mainly used for:
-
Exiting loops early
-
Skipping unnecessary iterations
-
Returning values from functions
-
Jumping to a labeled statement (rare use)
What Are Jump Statements?
Jump Statements in C++ are control statements that alter the normal execution sequence of a program by transferring control to a specific location or terminating the execution of loops or functions.
C++ provides four jump statements:
-
break
-
continue
-
goto
-
return
Types of Jump Statements in C++
1. break Statement
The break statement is used to immediately terminate a loop or switch statement and transfer control to the statement following the loop or switch.
Where Used
-
Inside loops (for, while, do-while)
-
Inside switch case
Syntax
break;
Example – Loop
#include <iostream>
using namespace std;
int main() {
for(int i = 1; i <= 10; i++) {
if(i == 6) {
break;
}
cout << i << " ";
}
return 0;
}
Output
1 2 3 4 5
Explanation
When i == 6, break executes and exits the loop immediately.
Real-Life Example
👉 Searching for a product:
-
Once product is found → stop searching
2. continue Statement
The continue statement is used to skip the current iteration of a loop and move directly to the next iteration.
Syntax
continue;
Example – Loop
#include <iostream>
using namespace std;
int main() {
for(int i = 1; i <= 5; i++) {
if(i == 3) {
continue;
}
cout << i << " ";
}
return 0;
}
Output
1 2 4 5
Explanation
When i == 3, the remaining loop statements are skipped for that iteration.
Real-Life Example
👉 Online exam:
-
Skip already answered questions
3. goto Statement
The goto statement transfers program control to a labeled statement within the same function.
📛 Note: Use of goto is strongly discouraged as it makes code hard to read and maintain.
Syntax
goto label;
label:
statement;
Example
#include <iostream>
using namespace std;
int main() {
int num = 1;
start:
if(num <= 3) {
cout << num << " ";
num++;
goto start;
}
return 0;
}
Output
1 2 3
Real-Life Example
👉 Emergency exit in a process (but structured loops are preferred)
4. return Statement
The return statement is used to:
-
Exit from a function
-
Optionally send a value back to the calling function
Syntax
return value;
or
return;
Example – Function with Return Value
#include <iostream>
using namespace std;
int add(int a, int b) {
return a + b;
}
int main() {
cout << add(10, 20);
return 0;
}
Output
30
Example – Exit Function Early
#include <iostream>
using namespace std;
int main() {
cout << "Start\n";
return 0;
cout << "End\n";
}
Output
Start
Real-Life Example
👉 ATM Machine:
-
After cash is withdrawn → return control to main menu
Comparison Table of Jump Statements
| Statement | Purpose | Used In |
|---|---|---|
break |
Exit loop/switch | Loop, Switch |
continue |
Skip current iteration | Loop |
goto |
Jump to label | Same function |
return |
Exit function | Function |
Practical Real-Life Use Cases
ATM Machine
if(balance == 0)
break;
Online Shopping Cart
if(productOutOfStock)
continue;
Function Execution
return totalAmount;
Best Practices
✅ Use break and continue wisely
✅ Prefer structured loops over goto
✅ Always use return for meaningful function exits
❌ Avoid excessive jump statements
❌ Avoid goto in professional code
Practice Questions
-
Print numbers from 1 to 20 but stop when number is 12
-
Skip multiples of 5 between 1 and 50
-
Exit a program if wrong password is entered
-
Demonstrate return statement in a calculator function
-
Print numbers using
goto(for understanding only)
Conclusion
Jump statements give programmers control power to manage loop execution and function flow.
When used properly, they improve efficiency and clarity.
Overuse or misuse, however, may reduce code readability.
Keep practicing — you're doing amazing!
Happy Coding! ![]()