C Programming • C Basics, Operators, Loops
C Programming / Unconditional control statements: break

Unconditional control statements: break

Notes 2 C Basics, Operators, Loops

Definition: The break statement is used to immediately terminate the nearest loop or switch-case statement. Program execution continues with the statement that follows the terminated loop or switch.

Notes

break Statement in C

Definition: The break statement is used to immediately terminate the nearest loop or switch-case statement. Program execution continues with the statement that follows the terminated loop or switch.

💡 Example: If a loop contains break when i == 5, the loop stops immediately at 5 and does not continue further.

Syntax

break;

How break Works

Loop starts ↓ Condition checked ↓ Statement executes ↓ break encountered? ↓ ↓ Yes No ↓ ↓ Exit loop Continue loop ↓ Next statement

Example

In the following example, the loop is stopped when the value of i becomes 3.

#include <stdio.h>

int main()
{
    int i;

    for (i = 1; i <= 5; i++)
    {
        if (i == 3)
            break;              // stop the loop when i becomes 3

        printf("%d ", i);
    }

    return 0;
}

Output

1 2

Why is break Used?

The break statement is used when the program needs to stop a loop immediately after a particular condition is satisfied.

💡 Example: While searching for a student's roll number in a list, the search can stop as soon as the required roll number is found.

break with for Loop

When break is used inside a for loop, the loop terminates immediately. The remaining iterations are skipped.

💡 Example: If a loop is set to run from 1 to 10 but break executes at 6, values 6 to 10 are not processed.

break with while Loop

The break statement can also terminate a while loop when a required condition is met.

💡 Example: A program can keep reading numbers until it receives a particular value, then use break to stop the loop.

break with switch-case

In a switch-case statement, break is commonly used to terminate the current case and prevent execution from falling into the next case.

💡 Example: After executing case 1, break exits the switch instead of continuing to case 2.

Practical Example — Stop When Number is Found

Problem Statement

Write a C program to search for the number 7 from 1 to 10. Stop the loop when the number 7 is reached using the break statement.

Learning Outcomes

  • Understand the purpose of the break statement.
  • Terminate a loop before its normal condition becomes false.
  • Use break with a conditional statement inside a loop.

Hint

Use a for loop from 1 to 10. When i == 7, use break to terminate the loop.

Theory

The break statement immediately terminates the nearest loop when it is executed. Control then moves to the statement after the loop.

Program

#include <stdio.h>

int main()
{
    int i;

    for (i = 1; i <= 10; i++)
    {
        if (i == 7)             // stop when 7 is reached
            break;

        printf("%d ", i);
    }

    return 0;
}

Expected Output

1 2 3 4 5 6

Note

break terminates only the nearest loop or switch in which it appears. It does not simply skip the current iteration; it completely exits the loop.

break vs continue

break continue
Terminates the loop completely. Skips the current iteration.
Control moves outside the loop. Control moves to the next iteration.
Used when no further repetition is required. Used when one particular iteration should be skipped.

Important Points for Exam

  • break immediately terminates the nearest loop or switch.
  • It can be used inside for, while and do-while loops.
  • It is also commonly used with switch-case.
  • After break, control moves to the statement after the loop or switch.
  • break is different from continue.
🎯 Easy Rule:

break = Stop the loop completely

Quick Revision

Concept Remember
Purpose Terminate the nearest loop or switch.
Syntax break;
Loops for, while, do-while
switch-case Prevents fall-through between cases.

Important Exam Questions

Short Answer Questions

  1. What is a break statement in C?
  2. Write the syntax of break.
  3. What happens when break is executed inside a loop?
  4. Where can the break statement be used?
  5. What is the use of break in switch-case?
  6. Differentiate between break and continue.

Long Answer Questions

  1. Explain the break statement with syntax and suitable example.
  2. Write a C program that uses break to terminate a loop when a particular value is reached.
  3. Explain the use of break in loops and switch-case.
🎥 Recommended Learning

Watch a beginner-friendly explanation of the break statement in C programming.

▶ Watch: break Statement in C — Hindi

📝 Handwritten Notes

A short handwritten-style revision sheet for the break statement will be provided here.

🧠 Mind Map

Use the mind map for quick revision of break, loop termination and switch-case.