SlideShare a Scribd company logo
2
Most read
3
Most read
6
Most read
The break and continue Statements
• break
– Causes immediate exit from a while, for, do/while or
switch structure
– Program execution continues with the first statement after the
structure
– Common uses of the break statement
• Escape early from a loop
• Skip the remainder of a switch structure
The break and continue Statements (II)
• continue
– Skips the remaining statements in the body of a while, for or
do/while structure
• Proceeds with the next iteration of the loop

– while and do/while
• Loop-continuation test is evaluated immediately after the
continue statement is executed

– for structure
• Increment expression is executed, then the loop-continuation test
is evaluated
1 /* Fig. 4.12: fig04_12.c
2
Using the continue statement in a for
3 #include <stdio.h>
structure */
4
5 int main()
6 {
7
int x;
8
9
for ( x = 1; x <= 10; x++ ) {
10
11
if ( x == 5 )
12
continue; /* skip remaining code in
13
if x == 5 */
loop only
14
15
printf( "%d ", x );
16
}
17
18
printf( "nUsed continue to skip printing
19
return 0;
the value 5n" );
20}
1 2 3 4 6 7 8 9 10
Used continue to skip printing the value 5
2000 Prentice Hall, Inc. All rights

Outline

1. Initialize variable
2. Loop

3. Print

Program Output
The break Keyword
Continuation
condition?
true
Statement(s)
break
Statement(s)

Next
Statement

false
break
// Using break to exit a loop (break.c).
#include <stdio.h>
main() {
int i;
for(i=0; i<100; i++) {
if(i == 10) break; // terminate loop if i is 10
printf("i: %d n", i);
}
printf("Loop complete.");
}
The continue Keyword
Continue
condition?
true
Statement(s)
continue
Statement(s)

Next
Statement

false

More Related Content

PPTX
Loops in c
PDF
10. switch case
PPTX
Loops Basics
PPTX
C Programming Language Tutorial for beginners - JavaTpoint
PPT
Introduction to C Programming
PPTX
Presentation on C Switch Case Statements
PPT
RECURSION IN C
Loops in c
10. switch case
Loops Basics
C Programming Language Tutorial for beginners - JavaTpoint
Introduction to C Programming
Presentation on C Switch Case Statements
RECURSION IN C

What's hot (20)

PPTX
Unit 3. Input and Output
PPTX
Functions in c language
PPTX
Functions in c++
PPTX
Operators in java
PPTX
Conditional Statement in C Language
PPTX
Control Flow Statements
PPTX
Stacks in c++
PPTX
If else statement in c++
PPTX
Recursive Function
PPTX
Break and continue in C
PPTX
C if else
PPTX
Function in C program
PPT
Decision making and looping
PPTX
Branching statements
PPTX
Exception handling c++
PPTX
Functions in c
PPTX
Type casting in c programming
PPTX
Loops in C Programming Language
PPTX
Inline function
Unit 3. Input and Output
Functions in c language
Functions in c++
Operators in java
Conditional Statement in C Language
Control Flow Statements
Stacks in c++
If else statement in c++
Recursive Function
Break and continue in C
C if else
Function in C program
Decision making and looping
Branching statements
Exception handling c++
Functions in c
Type casting in c programming
Loops in C Programming Language
Inline function
Ad

Viewers also liked (13)

PPSX
Break and continue statement in C
PPTX
Loops in C
PPT
C Programming (break and continue) - Coders Trust
PPTX
PDF
C Prog. - ASCII Values, Break, Continue
PPTX
C programming - String
DOC
String in c
PPTX
C++ loop
PPTX
Loops c++
PPTX
Loops in C Programming
PPT
Unit 6 pointers
PPSX
INTRODUCTION TO C PROGRAMMING
Break and continue statement in C
Loops in C
C Programming (break and continue) - Coders Trust
C Prog. - ASCII Values, Break, Continue
C programming - String
String in c
C++ loop
Loops c++
Loops in C Programming
Unit 6 pointers
INTRODUCTION TO C PROGRAMMING
Ad

Similar to Break and continue (20)

PPTX
C Programming Control Structures(if,if-else)
PPTX
Session05 iteration structure
PPT
9 cm604.13
PDF
175035-cse LAB-04
PPTX
C Programming Language Part 6
PPTX
C PPT.power point presentation about c pro
PPTX
C programming Control Structure.pptx
PDF
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
PPT
Lecture 10 - Control Structures 2
PPTX
break continue and pass statement in python.pptx
PDF
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PPTX
C language 2
PPTX
C Programming: Control Structure
PDF
PDF
PPTX
Decision Making and Looping
PPTX
Ch6 Loops
PDF
Unit II chapter 4 Loops in C
PPTX
Break,Pass and Continue.pptx
C Programming Control Structures(if,if-else)
Session05 iteration structure
9 cm604.13
175035-cse LAB-04
C Programming Language Part 6
C PPT.power point presentation about c pro
C programming Control Structure.pptx
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
Lecture 10 - Control Structures 2
break continue and pass statement in python.pptx
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
C language 2
C Programming: Control Structure
Decision Making and Looping
Ch6 Loops
Unit II chapter 4 Loops in C
Break,Pass and Continue.pptx

More from Frijo Francis (12)

PPSX
Type conversion
PPSX
Structure
PPSX
Recursion prog
PPSX
Recursion prog (1)
PPSX
Pointers
PPSX
Data type
PPSX
C programming language
PPSX
6 enumerated, typedef
PPSX
5bit field
PPSX
4 dynamic memory allocation
PPSX
PPSX
1file handling
Type conversion
Structure
Recursion prog
Recursion prog (1)
Pointers
Data type
C programming language
6 enumerated, typedef
5bit field
4 dynamic memory allocation
1file handling

Recently uploaded (20)

PPTX
Pharma ospi slides which help in ospi learning
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
01-Introduction-to-Information-Management.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Insiders guide to clinical Medicine.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Pre independence Education in Inndia.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Pharma ospi slides which help in ospi learning
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
GDM (1) (1).pptx small presentation for students
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
O7-L3 Supply Chain Operations - ICLT Program
01-Introduction-to-Information-Management.pdf
PPH.pptx obstetrics and gynecology in nursing
Microbial diseases, their pathogenesis and prophylaxis
Insiders guide to clinical Medicine.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Pre independence Education in Inndia.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Abdominal Access Techniques with Prof. Dr. R K Mishra
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Pharmacology of Heart Failure /Pharmacotherapy of CHF

Break and continue

  • 1. The break and continue Statements • break – Causes immediate exit from a while, for, do/while or switch structure – Program execution continues with the first statement after the structure – Common uses of the break statement • Escape early from a loop • Skip the remainder of a switch structure
  • 2. The break and continue Statements (II) • continue – Skips the remaining statements in the body of a while, for or do/while structure • Proceeds with the next iteration of the loop – while and do/while • Loop-continuation test is evaluated immediately after the continue statement is executed – for structure • Increment expression is executed, then the loop-continuation test is evaluated
  • 3. 1 /* Fig. 4.12: fig04_12.c 2 Using the continue statement in a for 3 #include <stdio.h> structure */ 4 5 int main() 6 { 7 int x; 8 9 for ( x = 1; x <= 10; x++ ) { 10 11 if ( x == 5 ) 12 continue; /* skip remaining code in 13 if x == 5 */ loop only 14 15 printf( "%d ", x ); 16 } 17 18 printf( "nUsed continue to skip printing 19 return 0; the value 5n" ); 20} 1 2 3 4 6 7 8 9 10 Used continue to skip printing the value 5 2000 Prentice Hall, Inc. All rights Outline 1. Initialize variable 2. Loop 3. Print Program Output
  • 5. break // Using break to exit a loop (break.c). #include <stdio.h> main() { int i; for(i=0; i<100; i++) { if(i == 10) break; // terminate loop if i is 10 printf("i: %d n", i); } printf("Loop complete."); }