SlideShare a Scribd company logo
C – LOOP
C – LOOP
 There may be a situation,
when you need to execute a
block of code several number
of times. In general,
statements are executed
sequentially: The first
statement in a function is
executed first, followed by the
second, and so on.
 A loop statement allows us to
execute a statement or group
of statements multiple times
and following is the general
form of a loop statement in
most of the programming
languages:
TYPES OF LOOP
Statement Description
1. for loop Execute a sequence of statements multiple times and
abbreviates the code that manages the loop variable.
2. while loop Repeats a statement or group of statements while a given
condition is true. It tests the condition before executing the
loop body.
3. do...while loop Like a while statement, except that it tests the
condition at the end of the loop body
4. nested loop You can use one or more loop inside any another while, for
or do..while loop.
C programming language provides the following types of loop to handle
looping requirements.
FOR LOOP
 A for loop is a repetition control structure that allows you to
efficiently write a loop that needs to execute a specific number
of times.
 Syntax:
FLOW OF CONTROL IN A FOR LOOP
 The init step is executed first, and only once. This step allows
you to declare and initialize any loop control variables. You are
not required to put a statement here, as long as a semicolon
appears.
 Next, the condition is evaluated. If it is true, the body of the loop
is executed. If it is false, the body of the loop does not execute
and flow of control jumps to the next statement just after the for
loop.
 After the body of the for loop executes, the flow of control jumps
back up to the increment statement. This statement allows you
to update any loop control variables. This statement can be left
blank, as long as a semicolon appears after the condition.
 The condition is now evaluated again. If it is true, the loop
executes and the process repeats itself (body of loop, then
increment step, and then again condition). After the condition
becomes false, the for loop terminates.
FLOW DIAGRAM : FOR LOOP
CODE EXAMPLE
Output:
2. WHILE LOOP
 A while loop statement repeatedly executes a target
statement as long as a given condition is true.
 Syntax:
 Here, statement(s) may be a single statement or a block of
statements.
 The condition may be any expression, and true is any nonzero
value. The loop iterates while the condition is true.
 When the condition becomes false, program control passes to
the line immediately following the loop.
FLOW DIAGRAM: WHILE LOOP
Here, key point of the while loop is that the loop might not ever run. When the
condition is tested and the result is false, the loop body will be skipped and the
first statement after the while loop will be executed.
CODE EXAMPLE : IF ELSE
Output:
3. DO..WHILE LOOP
 Unlike for and while loops, which test the loop condition at the
top of the loop, the do...while loop in checks its condition at the
bottom of the loop.
 A do...while loop is similar to a while loop, except that a
do...while loop is guaranteed to execute at least one time.
 Syntax:
 Notice that the conditional expression appears at the end of the
loop, so the statement(s) in the loop execute once before the
condition is tested.
 If the condition is true, the flow of control jumps back up to do,
and the statement(s) in the loop execute again. This process
repeats until the given condition becomes false.
FLOW DIAGRAM: DO..WHILE LOOP
CODE EXAMPLE: DO...WHILE
Output:
NESTED LOOPS IN C
 It is allow to use one loop inside another loop.
 The syntax for a nested for loop statement
 The syntax for a nested while loop statement
NESTED LOOPS IN C
 The syntax for a nested do...while loop
 A final note on loop nesting is that you can put any type of
loop inside of any other type of loop. For example, a for loop
can be inside a while loop or vice versa.
CODE EXAMPLE NESTED FOR LOOP
CODE EXAMPLE NESTED FOR LOOP
LOOP CONTROL STATEMENTS:
Loop control statements change execution from its normal
sequence. C supports the following control statements.
Control Statement Description
break statement Terminates the loop or switch statement and transfers
execution to the statement immediately following the loop
or switch.
continue statement Causes the loop to skip the remainder of its body and
immediately retest its condition prior to reiterating.
BREAK STATEMENT
 The break statement in C programming language has
the following two usages:
 When the break statement is encountered inside a loop, the
loop is immediately terminated and program control resumes
at the next statement following the loop.
 It can be used to terminate a case in the switch statement (we
already saw).
 If you are using nested loops (i.e., one loop inside
another loop), the break statement will stop the execution
of the innermost loop and start executing the next line of
code after the block.
 Syntax:
break;
FLOW DIAGRAM: BREAK STATEMENT
CODE EXAMPLE: BREAK
BREAK
CONTINUE STATEMENT
 The continue statement works somewhat like the break
statement. Instead of forcing termination, however,
continue forces the next iteration of the loop to take
place, skipping any code in between.
 For the for loop, continue statement causes the
conditional test and increment portions of the loop to
execute. For the while and do...while loops, continue
statement causes the program control passes to the
conditional tests.
 Syntax:
continue;
FLOW DIAGRAM: CONTINUE
CODE EXAMPLE: CONTINUE
value of i: 0
value of i: 1
value of i: 2
value of i: 4
value of i: 5
Notice that
3 is not
there!
CONTINUE
Ad

More Related Content

What's hot (20)

Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7
MLG College of Learning, Inc
 
Computer programming 2 Lesson 9
Computer programming 2  Lesson 9Computer programming 2  Lesson 9
Computer programming 2 Lesson 9
MLG College of Learning, Inc
 
Flow of Control
Flow of ControlFlow of Control
Flow of Control
Praveen M Jigajinni
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
Raj Parekh
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
Deepak Lakhlan
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
baabtra.com - No. 1 supplier of quality freshers
 
Decision control structures
Decision control structuresDecision control structures
Decision control structures
Rahul Bathri
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
Jayfee Ramos
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
Hossain Md Shakhawat
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
Kamal Acharya
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
Mohammed Sikander
 
C language control statements
C language  control statementsC language  control statements
C language control statements
suman Aggarwal
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
University of Potsdam
 
M C6java5
M C6java5M C6java5
M C6java5
mbruggen
 
M C6java6
M C6java6M C6java6
M C6java6
mbruggen
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
It Academy
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
TANUJ ⠀
 
Java loops for, while and do...while
Java loops   for, while and do...whileJava loops   for, while and do...while
Java loops for, while and do...while
Jayfee Ramos
 
Java control flow statements
Java control flow statementsJava control flow statements
Java control flow statements
Future Programming
 
Switch statement, break statement, go to statement
Switch statement, break statement, go to statementSwitch statement, break statement, go to statement
Switch statement, break statement, go to statement
Raj Parekh
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
Deepak Lakhlan
 
Decision control structures
Decision control structuresDecision control structures
Decision control structures
Rahul Bathri
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
Jayfee Ramos
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
Kamal Acharya
 
C language control statements
C language  control statementsC language  control statements
C language control statements
suman Aggarwal
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
It Academy
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
TANUJ ⠀
 
Java loops for, while and do...while
Java loops   for, while and do...whileJava loops   for, while and do...while
Java loops for, while and do...while
Jayfee Ramos
 

Similar to Cse lecture-7-c loop (20)

Computer programming 2 Lesson 8
Computer programming 2  Lesson 8Computer programming 2  Lesson 8
Computer programming 2 Lesson 8
MLG College of Learning, Inc
 
C language 2
C language 2C language 2
C language 2
Arafat Bin Reza
 
Loops Basics
Loops BasicsLoops Basics
Loops Basics
Mushiii
 
Cpp loop types
Cpp loop typesCpp loop types
Cpp loop types
Rj Baculo
 
Loops in c
Loops in cLoops in c
Loops in c
RekhaBudhwar
 
Loops
LoopsLoops
Loops
Mohammed Alhafyan
 
Loops
LoopsLoops
Loops
ShivamPatel466
 
Loop in C Properties & Applications
Loop in C Properties & ApplicationsLoop in C Properties & Applications
Loop in C Properties & Applications
Emroz Sardar
 
R loops
R   loopsR   loops
R loops
Learnbay Datascience
 
Loop structures
Loop structuresLoop structures
Loop structures
tazeem sana
 
Chapter 9 - Loops in C++
Chapter 9 - Loops in C++Chapter 9 - Loops in C++
Chapter 9 - Loops in C++
Deepak Singh
 
Java Repetiotion Statements
Java Repetiotion StatementsJava Repetiotion Statements
Java Repetiotion Statements
Huda Alameen
 
Chapter 3 - Flow of Control Part II.pdf
Chapter 3  - Flow of Control Part II.pdfChapter 3  - Flow of Control Part II.pdf
Chapter 3 - Flow of Control Part II.pdf
KirubelWondwoson1
 
DECISION MAKING.pptx
DECISION MAKING.pptxDECISION MAKING.pptx
DECISION MAKING.pptx
Ayshwarya Baburam
 
2nd year computer science chapter 12 notes
2nd year computer science chapter 12 notes2nd year computer science chapter 12 notes
2nd year computer science chapter 12 notes
muhammadFaheem656405
 
Loops in C.net.pptx
Loops in C.net.pptxLoops in C.net.pptx
Loops in C.net.pptx
Fajela
 
What is loops? What is For loop?
What is loops? What is For loop?What is loops? What is For loop?
What is loops? What is For loop?
AnuragSrivastava272
 
python.pptx
python.pptxpython.pptx
python.pptx
Poornima116356
 
presentation on powerpoint template.pptx
presentation on powerpoint template.pptxpresentation on powerpoint template.pptx
presentation on powerpoint template.pptx
farantouqeer8
 
Do While Repetition Structure
Do While Repetition StructureDo While Repetition Structure
Do While Repetition Structure
Shahzu2
 
Ad

Recently uploaded (20)

Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Development of MLR, ANN and ANFIS Models for Estimation of PCUs at Different ...
Journal of Soft Computing in Civil Engineering
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...15th International Conference on Computer Science, Engineering and Applicatio...
15th International Conference on Computer Science, Engineering and Applicatio...
IJCSES Journal
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
IntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdfIntroSlides-April-BuildWithAI-VertexAI.pdf
IntroSlides-April-BuildWithAI-VertexAI.pdf
Luiz Carneiro
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G..."Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
"Feed Water Heaters in Thermal Power Plants: Types, Working, and Efficiency G...
Infopitaara
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
Level 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical SafetyLevel 1-Safety.pptx Presentation of Electrical Safety
Level 1-Safety.pptx Presentation of Electrical Safety
JoseAlbertoCariasDel
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Introduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptxIntroduction to Zoomlion Earthmoving.pptx
Introduction to Zoomlion Earthmoving.pptx
AS1920
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
Ad

Cse lecture-7-c loop

  • 2. C – LOOP  There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.  A loop statement allows us to execute a statement or group of statements multiple times and following is the general form of a loop statement in most of the programming languages:
  • 3. TYPES OF LOOP Statement Description 1. for loop Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable. 2. while loop Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. 3. do...while loop Like a while statement, except that it tests the condition at the end of the loop body 4. nested loop You can use one or more loop inside any another while, for or do..while loop. C programming language provides the following types of loop to handle looping requirements.
  • 4. FOR LOOP  A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.  Syntax:
  • 5. FLOW OF CONTROL IN A FOR LOOP  The init step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears.  Next, the condition is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and flow of control jumps to the next statement just after the for loop.  After the body of the for loop executes, the flow of control jumps back up to the increment statement. This statement allows you to update any loop control variables. This statement can be left blank, as long as a semicolon appears after the condition.  The condition is now evaluated again. If it is true, the loop executes and the process repeats itself (body of loop, then increment step, and then again condition). After the condition becomes false, the for loop terminates.
  • 6. FLOW DIAGRAM : FOR LOOP
  • 8. 2. WHILE LOOP  A while loop statement repeatedly executes a target statement as long as a given condition is true.  Syntax:  Here, statement(s) may be a single statement or a block of statements.  The condition may be any expression, and true is any nonzero value. The loop iterates while the condition is true.  When the condition becomes false, program control passes to the line immediately following the loop.
  • 9. FLOW DIAGRAM: WHILE LOOP Here, key point of the while loop is that the loop might not ever run. When the condition is tested and the result is false, the loop body will be skipped and the first statement after the while loop will be executed.
  • 10. CODE EXAMPLE : IF ELSE Output:
  • 11. 3. DO..WHILE LOOP  Unlike for and while loops, which test the loop condition at the top of the loop, the do...while loop in checks its condition at the bottom of the loop.  A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.  Syntax:  Notice that the conditional expression appears at the end of the loop, so the statement(s) in the loop execute once before the condition is tested.  If the condition is true, the flow of control jumps back up to do, and the statement(s) in the loop execute again. This process repeats until the given condition becomes false.
  • 14. NESTED LOOPS IN C  It is allow to use one loop inside another loop.  The syntax for a nested for loop statement  The syntax for a nested while loop statement
  • 15. NESTED LOOPS IN C  The syntax for a nested do...while loop  A final note on loop nesting is that you can put any type of loop inside of any other type of loop. For example, a for loop can be inside a while loop or vice versa.
  • 18. LOOP CONTROL STATEMENTS: Loop control statements change execution from its normal sequence. C supports the following control statements. Control Statement Description break statement Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch. continue statement Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating.
  • 19. BREAK STATEMENT  The break statement in C programming language has the following two usages:  When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop.  It can be used to terminate a case in the switch statement (we already saw).  If you are using nested loops (i.e., one loop inside another loop), the break statement will stop the execution of the innermost loop and start executing the next line of code after the block.  Syntax: break;
  • 20. FLOW DIAGRAM: BREAK STATEMENT
  • 22. BREAK
  • 23. CONTINUE STATEMENT  The continue statement works somewhat like the break statement. Instead of forcing termination, however, continue forces the next iteration of the loop to take place, skipping any code in between.  For the for loop, continue statement causes the conditional test and increment portions of the loop to execute. For the while and do...while loops, continue statement causes the program control passes to the conditional tests.  Syntax: continue;
  • 25. CODE EXAMPLE: CONTINUE value of i: 0 value of i: 1 value of i: 2 value of i: 4 value of i: 5 Notice that 3 is not there!