SlideShare uma empresa Scribd logo
1 de 6
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

Mais conteúdo relacionado

Mais procurados

Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareGagan Deep
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator OverloadingNilesh Dalvi
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++Sachin Yadav
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c languagesneha2494
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programmingKamal Acharya
 
Functions in c language
Functions in c language Functions in c language
Functions in c language tanmaymodi4
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in CHarendra Singh
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptxSKUP1
 
While loop
While loopWhile loop
While loopFeras_83
 
Branching statements
Branching statementsBranching statements
Branching statementsArunMK17
 

Mais procurados (20)

Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Structure in C
Structure in CStructure in C
Structure in C
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Call by value or call by reference in C++
Call by value or call by reference in C++Call by value or call by reference in C++
Call by value or call by reference in C++
 
The Loops
The LoopsThe Loops
The Loops
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
stack & queue
stack & queuestack & queue
stack & queue
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
 
While loop
While loopWhile loop
While loop
 
Branching statements
Branching statementsBranching statements
Branching statements
 

Destaque (12)

Break and continue statement in C
Break and continue statement in CBreak and continue statement in C
Break and continue statement in C
 
Loops in C
Loops in CLoops in C
Loops in C
 
C Programming (break and continue) - Coders Trust
C Programming (break and continue) -  Coders TrustC Programming (break and continue) -  Coders Trust
C Programming (break and continue) - Coders Trust
 
Strrev
StrrevStrrev
Strrev
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
C Prog. - ASCII Values, Break, Continue
C Prog. -  ASCII Values, Break, ContinueC Prog. -  ASCII Values, Break, Continue
C Prog. - ASCII Values, Break, Continue
 
C programming - String
C programming - StringC programming - String
C programming - String
 
String in c
String in cString in c
String in c
 
C++ loop
C++ loop C++ loop
C++ loop
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
 
INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
 

Semelhante a Break and continue

Break, continue and return
Break, continue and return Break, continue and return
Break, continue and return Jadavsejal
 
Object oriented programming18 control structures looping
Object oriented programming18 control structures loopingObject oriented programming18 control structures looping
Object oriented programming18 control structures loopingVaibhav Khanna
 
Control structures repetition
Control structures   repetitionControl structures   repetition
Control structures repetitionOnline
 
ECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/SnaptutorialECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/Snaptutorialpinck2380
 
ECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/SnaptutorialECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/Snaptutorialpinck200
 
Ecet 360 Enthusiastic Study / snaptutorial.com
Ecet 360 Enthusiastic Study / snaptutorial.comEcet 360 Enthusiastic Study / snaptutorial.com
Ecet 360 Enthusiastic Study / snaptutorial.comStephenson34
 
Ecet 360 Success Begins / snaptutorial.com
Ecet 360  Success Begins / snaptutorial.comEcet 360  Success Begins / snaptutorial.com
Ecet 360 Success Begins / snaptutorial.comWilliamsTaylorzl
 
Ecet 360 Massive Success / snaptutorial.com
Ecet 360 Massive Success / snaptutorial.comEcet 360 Massive Success / snaptutorial.com
Ecet 360 Massive Success / snaptutorial.comHarrisGeorgx
 
Control structures.ppt
Control structures.pptControl structures.ppt
Control structures.pptRahul Borate
 
Loop control structure
Loop control structureLoop control structure
Loop control structurenarmadhakin
 
Break,Pass and Continue.pptx
Break,Pass and Continue.pptxBreak,Pass and Continue.pptx
Break,Pass and Continue.pptxUjjwalGupta604782
 
03 conditions loops
03   conditions loops03   conditions loops
03 conditions loopsManzoor ALam
 
Control Statement IN C.pptx
Control Statement IN C.pptxControl Statement IN C.pptx
Control Statement IN C.pptxsujatha629799
 
control statements
control statementscontrol statements
control statementsAzeem Sultan
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmSouvik Roy
 
Lab 3 of 7 Process Management Simulation L A B  O V E R V I E W.docx
Lab 3 of 7 Process Management Simulation L A B  O V E R V I E W.docxLab 3 of 7 Process Management Simulation L A B  O V E R V I E W.docx
Lab 3 of 7 Process Management Simulation L A B  O V E R V I E W.docxfestockton
 

Semelhante a Break and continue (20)

Break, continue and return
Break, continue and return Break, continue and return
Break, continue and return
 
Object oriented programming18 control structures looping
Object oriented programming18 control structures loopingObject oriented programming18 control structures looping
Object oriented programming18 control structures looping
 
Control structures repetition
Control structures   repetitionControl structures   repetition
Control structures repetition
 
ECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/SnaptutorialECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/Snaptutorial
 
ECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/SnaptutorialECET 360 help A Guide to career/Snaptutorial
ECET 360 help A Guide to career/Snaptutorial
 
Ecet 360 Enthusiastic Study / snaptutorial.com
Ecet 360 Enthusiastic Study / snaptutorial.comEcet 360 Enthusiastic Study / snaptutorial.com
Ecet 360 Enthusiastic Study / snaptutorial.com
 
Ecet 360 Success Begins / snaptutorial.com
Ecet 360  Success Begins / snaptutorial.comEcet 360  Success Begins / snaptutorial.com
Ecet 360 Success Begins / snaptutorial.com
 
Ecet 360 Massive Success / snaptutorial.com
Ecet 360 Massive Success / snaptutorial.comEcet 360 Massive Success / snaptutorial.com
Ecet 360 Massive Success / snaptutorial.com
 
ch5.ppt
ch5.pptch5.ppt
ch5.ppt
 
M C6java6
M C6java6M C6java6
M C6java6
 
Control structures.ppt
Control structures.pptControl structures.ppt
Control structures.ppt
 
Loop control structure
Loop control structureLoop control structure
Loop control structure
 
Break,Pass and Continue.pptx
Break,Pass and Continue.pptxBreak,Pass and Continue.pptx
Break,Pass and Continue.pptx
 
03 conditions loops
03   conditions loops03   conditions loops
03 conditions loops
 
Ch05
Ch05Ch05
Ch05
 
Control Statement IN C.pptx
Control Statement IN C.pptxControl Statement IN C.pptx
Control Statement IN C.pptx
 
175035-cse LAB-04
175035-cse LAB-04 175035-cse LAB-04
175035-cse LAB-04
 
control statements
control statementscontrol statements
control statements
 
Mutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's AlgorithmMutual Exclusion using Peterson's Algorithm
Mutual Exclusion using Peterson's Algorithm
 
Lab 3 of 7 Process Management Simulation L A B  O V E R V I E W.docx
Lab 3 of 7 Process Management Simulation L A B  O V E R V I E W.docxLab 3 of 7 Process Management Simulation L A B  O V E R V I E W.docx
Lab 3 of 7 Process Management Simulation L A B  O V E R V I E W.docx
 

Mais de Frijo Francis (12)

Type conversion
Type conversionType conversion
Type conversion
 
Structure
StructureStructure
Structure
 
Recursion prog
Recursion progRecursion prog
Recursion prog
 
Recursion prog (1)
Recursion prog (1)Recursion prog (1)
Recursion prog (1)
 
Pointers
PointersPointers
Pointers
 
Data type
Data typeData type
Data type
 
C programming language
C programming languageC programming language
C programming language
 
6 enumerated, typedef
6 enumerated, typedef6 enumerated, typedef
6 enumerated, typedef
 
5bit field
5bit field5bit field
5bit field
 
4 dynamic memory allocation
4 dynamic memory allocation4 dynamic memory allocation
4 dynamic memory allocation
 
Union
UnionUnion
Union
 
1file handling
1file handling1file handling
1file handling
 

Último

Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxnelietumpap1
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 

Último (20)

Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Q4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptxQ4 English4 Week3 PPT Melcnmg-based.pptx
Q4 English4 Week3 PPT Melcnmg-based.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 

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."); }