SlideShare a Scribd company logo
1 of 26
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

More Related Content

What's hot

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 statementRaj Parekh
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlanDeepak Lakhlan
 
Decision control structures
Decision control structuresDecision control structures
Decision control structuresRahul Bathri
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision ControlJayfee Ramos
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C pptMANJUTRIPATHI7
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C ProgrammingKamal Acharya
 
C language control statements
C language  control statementsC language  control statements
C language control statementssuman Aggarwal
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsIt Academy
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJTANUJ ⠀
 
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...whileJayfee Ramos
 

What's hot (20)

Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7Computer programming 2 - Lesson 7
Computer programming 2 - Lesson 7
 
Computer programming 2 Lesson 9
Computer programming 2  Lesson 9Computer programming 2  Lesson 9
Computer programming 2 Lesson 9
 
Flow of Control
Flow of ControlFlow of Control
Flow of Control
 
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
 
Flow of control by deepak lakhlan
Flow of control by deepak lakhlanFlow of control by deepak lakhlan
Flow of control by deepak lakhlan
 
C# conditional branching statement
C# conditional branching statementC# conditional branching statement
C# conditional branching statement
 
Decision control structures
Decision control structuresDecision control structures
Decision control structures
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
Decision making and branching
Decision making and branchingDecision making and branching
Decision making and branching
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
C language control statements
C language  control statementsC language  control statements
C language control statements
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
M C6java5
M C6java5M C6java5
M C6java5
 
M C6java6
M C6java6M C6java6
M C6java6
 
Chapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java StatementsChapter 2 : Programming with Java Statements
Chapter 2 : Programming with Java Statements
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By 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
 
Java control flow statements
Java control flow statementsJava control flow statements
Java control flow statements
 

Similar to Cse lecture-7-c loop

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
 
C language 2
C language 2C language 2
C language 2
 
Loops Basics
Loops BasicsLoops Basics
Loops Basics
 
Cpp loop types
Cpp loop typesCpp loop types
Cpp loop types
 
Loops in c
Loops in cLoops in c
Loops in c
 
Loops
LoopsLoops
Loops
 
Loops
LoopsLoops
Loops
 
Loop in C Properties & Applications
Loop in C Properties & ApplicationsLoop in C Properties & Applications
Loop in C Properties & Applications
 
R loops
R   loopsR   loops
R loops
 
Loop structures
Loop structuresLoop structures
Loop structures
 
Chapter 9 - Loops in C++
Chapter 9 - Loops in C++Chapter 9 - Loops in C++
Chapter 9 - Loops in C++
 
Java Repetiotion Statements
Java Repetiotion StatementsJava Repetiotion Statements
Java Repetiotion Statements
 
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
 
DECISION MAKING.pptx
DECISION MAKING.pptxDECISION MAKING.pptx
DECISION MAKING.pptx
 
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
 
Loops in C.net.pptx
Loops in C.net.pptxLoops in C.net.pptx
Loops in C.net.pptx
 
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?
 
python.pptx
python.pptxpython.pptx
python.pptx
 
Do While Repetition Structure
Do While Repetition StructureDo While Repetition Structure
Do While Repetition Structure
 
loops in C ppt.pdf
loops in C ppt.pdfloops in C ppt.pdf
loops in C ppt.pdf
 

Recently uploaded

Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesPrabhanshu Chaturvedi
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 

Recently uploaded (20)

Glass Ceramics: Processing and Properties
Glass Ceramics: Processing and PropertiesGlass Ceramics: Processing and Properties
Glass Ceramics: Processing and Properties
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 

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!