0% found this document useful (0 votes)
3 views3 pages

Break and Continue Statements

The document explains the break and continue statements in C, which are used to control the flow of loops. The break statement allows for premature exit from loops or switch statements, transferring control to the statement following the loop. Examples illustrate the use of break in for loops, while loops, and switch statements.

Uploaded by

kethanacse29922
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Break and Continue Statements

The document explains the break and continue statements in C, which are used to control the flow of loops. The break statement allows for premature exit from loops or switch statements, transferring control to the statement following the loop. Examples illustrate the use of break in for loops, while loops, and switch statements.

Uploaded by

kethanacse29922
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Break and Continue Statements in C

The break and continue statements are control flow statements in C that alter the normal flow of
a loop. These statements allow greater flexibility in managing loop execution.

. 1. break Statement

The break statement is used to exit from a loop or switch statement prematurely. When a break is
encountered, the control exits the current loop or switch block and moves to the first statement
following the loop or switch.

Syntax: break;

How It Works

1. The break is usually used with conditional statements.


2. When the break statement is executed, the program immediately exits the loop or switch.
3. Control is transferred to the statement immediately following the loop or switch.

Examples

Example 1: break in a for Loop

Exit the loop when the condition is met.

#include <stdio.h>

int main() {

for (int i = 1; i <= 10; i++) {

if (i == 5) {

break; // Exit the loop when i equals 5

printf("%d\n", i);

return 0;
}

Output: 1

Example 2: break in a while Loop

Exit the loop based on a condition.

#include <stdio.h>

int main() {

int i = 1;

while (i <= 10) {

if (i == 5) {

break; // Exit the loop when i equals 5

printf("%d\n", i);

i++;

return 0;

Output: 1

3
4

Example 3: break in a switch Statement

Terminate a switch case block.

#include <stdio.h>

int main() {

int num = 2;

switch (num) {

case 1:

printf("Case 1\n");

break;

case 2:

printf("Case 2\n");

break; // Exit the switch block

case 3:

printf("Case 3\n");

break;

default:

printf("Default case\n");

return 0;

Output: Case 2

You might also like