Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Jump Statements: break, continue, and goto

Lesson 15 of 53 in the free Foundation of C & C++ notes on Siksha Sarovar, written by Rohit Jangra.

Altering the Natural Flow

Sometimes the standard loop conditions aren't enough. C provides three "jump" statements to override the normal behavior of loops and switches.

1. break (The Emergency Exit)

Instantly terminates the innermost loop or switch statement. It "breaks" out of the block and continues with the first line of code after the block.

for (int i = 1; i <= 100; i++) {
    if (i == 13) break; // Exit early if we hit 13
    printf("%d ", i);
}
// Output: 1 2 3 ... 12

2. continue (The Skip Iteration)

Skips the rest of the body for the current iteration and jumps straight to the next update/condition check. It's like saying "I'm done with this specific item, give me the next one."

for (int i = 1; i <= 10; i++) {
    if (i % 2 == 0) continue; // Skip even numbers
    printf("%d ", i);
}
// Output: 1 3 5 7 9

3. goto (The Dangerous Jump)

Performs an unconditional jump to a labeled part of your code.

    if (fatalError) goto cleanup;
    // ...
cleanup:
    free(memory);
    printf("Goodbye.\n");

Why goto is controversial

Almost every beginner is told "Never use goto." Why? Because it makes the logic of your program jump around like a tangled bowl of noodles (called Spaghetti Code). It makes debugging nearly impossible. In 99.9% of cases, you can use a cleaner while loop or a function instead.

A break statement only exits the innermost loop. If you have a loop inside a loop, a break in the inner one will not stop the outer one! To exit multiple loops at once, you might need to use a flag variable or (the only valid use case) a goto.