📚 C Programming Tutorial

C Programming

Learn C programming concepts with simple explanations, examples and practical notes.

← Back to C Programming

Jump Statements

What are jump statements?

Imagine you are watching a movie. Normally, the movie plays scene by scene. But sometimes you may want to stop watching, skip a scene, jump to a particular scene, or finish the movie.

C programming also provides statements that change the normal flow of execution. These are called jump statements.

Definition: Jump statements are control statements in C that transfer program control from its normal sequence to another point in the program.

C has four commonly taught jump statements:

1. break — Stop

Immediately exits the nearest enclosing loop or switch statement.

Think: “Stop here!”

2. continue — Skip

Skips the remaining statements in the current loop iteration and proceeds to the next iteration.

Think: “Skip this turn!”

3. goto — Jump to a label

Transfers control to a labelled statement in the same function.

Think: “Go directly there!”

4. return — Leave a function

Ends the current function and can send a value back to the calling function.

Think: “My task is complete!”

break statement

The break statement immediately terminates the nearest enclosing loop or switch. Execution continues with the first statement after it.

Syntax

break;

Example: Stop counting at 4

#include <stdio.h>

int main(void)
{
    int i;

    for (i = 1; i <= 6; i++)
    {
        if (i == 4)
        {
            break;
        }

        printf("%d ", i);
    }

    return 0;
}
Output
1 2 3

How does it work?

Start loop: i = 1→ Check: i == 4 ?→ NO: print number and continue YES: execute break→ Exit the loop

Important points

  • break can be used in for, while, do-while, and switch.
  • It exits only the nearest enclosing loop or switch.
  • It does not automatically terminate the entire program.
Real-life example: Searching for a student in a list. Once the student is found, stop searching.

continue statement

The continue statement skips the remaining statements in the current loop iteration and moves to the next iteration.

Syntax

continue;

Example: Print numbers from 1 to 6, except 4

#include <stdio.h>

int main(void)
{
    int i;

    for (i = 1; i <= 6; i++)
    {
        if (i == 4)
        {
            continue;
        }

        printf("%d ", i);
    }

    return 0;
}
Output
1 2 3 5 6

When i becomes 4, continue skips printf(). The loop then proceeds to the next iteration.

Difference between break and continue

breakcontinue
ActionExits the loopSkips one iteration
Numbers printed (at 4)1 2 3  (Stop)1 2 3 4 5 6  (4 skipped)
Important exam point: In a for loop, continue moves to the update expression and then the condition check. In a while loop, the condition is checked again. Ensure your loop variable still progresses so you do not create an infinite loop.

goto statement

The goto statement transfers control directly to a labelled statement within the same function.

Syntax

goto label;

/* Other statements */

label:
    statement;

Here, label is an identifier followed by a colon.

Example

#include <stdio.h>

int main(void)
{
    printf("Start\n");

    goto finish;

    printf("This line is skipped.\n");

finish:
    printf("Program reached finish.\n");

    return 0;
}
Output
Start
Program reached finish.

Explanation

  1. Start is printed.
  2. goto finish; transfers control to the label finish:.
  3. The intervening printf() statement is skipped.
  4. The final message is printed.

Advantages and disadvantages

  • It can be useful in some carefully designed error-handling or cleanup paths.
  • Excessive use makes programs difficult to read, understand, and debug.
  • Prefer loops, functions, and structured control statements whenever possible.

return statement

Meaning

The return statement terminates the execution of the current function and transfers control back to the calling function.

It is commonly used in two forms:

return;        /* No value: void function */
return value;  /* Return a value */

Example: Return the square of a number

#include <stdio.h>

int square(int n)
{
    return n * n;
}

int main(void)
{
    int result = square(5);

    printf("Square = %d\n", result);

    return 0;
}
Output
Square = 25

How it works

  • square(5) calls the function with n = 5.
  • return n * n; calculates and sends back 25.
  • The value is stored in result.
  • main() prints the result and returns 0.
Remember: A function declared with return type void must not return a value. A non-void function should return an appropriate value when its result is required. Reaching the closing brace of main() is equivalent to returning 0 in C.

Comparison table

Featurebreakcontinuegotoreturn
Main purposeExit loop or switchSkip current loop iterationJump to a labelExit current function
Used with loopsYesYesCan transfer control around codeCan exit a function containing a loop
Used in switchYesNo, not to skip a casePossible, but use carefullyYes, exits the function
Returns a valueNoNoNoCan return a value
Good memory wordStopSkipJumpFinish

Common mistakes to avoid

  • Confusing break with continue.
  • Using continue outside a loop.
  • Forgetting to update a loop variable when using continue in a while loop.
  • Using goto without defining the target label in the same function.
  • Returning a value that is inconsistent with the function's declared return type.
  • Assuming break exits all nested loops; it exits only the nearest enclosing loop or switch.

Important questions for B.Tech exams

Short-answer questions

  1. Define jump statements in C and list their types.
  2. Differentiate between break and continue.
  3. Explain the syntax and purpose of goto.
  4. What is the role of return in a function?

Long-answer and programming questions

  1. Explain the four jump statements with suitable examples.
  2. Write a C program to print numbers from 1 to 10, skipping 5 using continue.
  3. Write a C program that stops printing numbers when the counter reaches 6 using break.
  4. Write a function that returns the larger of two integers using return.