×

Advanced Coding & Software Engineering Program

Duration: 1 Year (12 Months)

Join our premium 1-year program to master cutting-edge technologies and become an industry-ready Software Engineer!

Course Coverage

  • Languages: C, C++, Java, JavaScript, Python
  • Web Technologies: HTML, CSS, Bootstrap 5, MERN Stack, Full Stack Development
  • Databases: MySQL, MongoDB
  • Data Science Libraries: Pandas, NumPy
  • Development Tools: Visual Studio Code, IntelliJ IDEA, PyCharm, Postman, Git, GitHub
  • Cloud Platforms: Vercel, MongoDB Atlas

Program Highlights

  • Live Classes: Interactive sessions with real-time doubt resolution
  • Hands-On Sessions: Practical coding exercises to build real-world skills
  • Industry Experts: Learn from professionals with years of experience
  • Live Project: Work on real-world projects to apply your skills
  • Get Certificate: Earn a professional certificate upon program completion

Course Fee: Only ₹1020 / month
Limited Period Offer!

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:

  1.  break 

  2.  continue 

  3.  goto 

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

  1. Print numbers from 1 to 20 but stop when number is 12

  2. Skip multiples of 5 between 1 and 50

  3. Exit a program if wrong password is entered

  4. Demonstrate return statement in a calculator function

  5. 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!    yes


Online - Chat Now
Let’s Connect

Inquiry Sent!

Your message has been successfully sent. We'll get back to you soon!

iKeySkills Logo