SlideShare a Scribd company logo
1 of 13
Deogiri college, Aurangabad
Topic : Loops in c
Subject : Programming in c
Class : BCA(1st yr. )
By : shubham Narayan pandav
There are mainly two types of loops:
loops
Entry
control loop
For loop
While
loop
Exit control
loop
Do while
Entry control loop
 An entry control loop checks the condition at the time of entry
and if condition or expression becomes true then control
transfers into the body of the loop.
Entry
control loop
For loop while loop
 for Loop :-
The syntax of for loop is :
for (initializationStatement; testExpression; updateStatement)
{
// body of loop
}
The initialization statement is executed only once.
Then, the test expression is evaluated. If the test expression is
evaluated to false, the for loop is terminated.
If the test expression is evaluated to true, statement inside the
body of for loop are executed and the update expression is
updated
This process goes on until the test expression become false.
How for loop works?
Flowchart of for loop
1 2 3 4 5 6 7 8 9 10
Example 1
output :-
Program :-
Example 2
// Print numbers from 10 to 1
#include <stdio.h>
void main()
{
int i;
for (i = 10; i >=1; i--)
{
printf("%d ", i);
}
} // end of main
10 9 8 7 6 5 4 3 2 1
output :-
// Print numbers from 1 to 10
#include <stdio.h>
void main()
{
int i;
for (i = 1; i <= 10; i++)
{
printf("%d ", i);
}
} // end of main
 While loop
The syntax of while loop is :
How while loop works?
while (testExpression)
{
// body of the loop
}
 if the expression Is true, statements inside the body of while
loop are executed. Then, the test expression is evaluated
again.
 The process of goes on until the expression is evaluated to
false.
 If the expression is false, the loop terminates(Ends).
Flowchart of while loop
// program to print table
#include <stdio.h>
void main()
{
int i = 1, number;
printf("Enter a number : ");
scanf("%d", &number);
while (i <= 10)
{
printf("n%d * %d = %d",i,number,i*number);
i++;
}
}
1 * 8 = 8
2 * 8 = 16
3 * 8 = 24
4 * 8 = 32
5 * 8 = 40
6 * 8 = 48
7 * 8 = 56
8 * 8 = 64
9 * 8 = 72
10 * 8 = 80
Program :- output :-
Enter a number : 8
Example 1
Exit control loop
 An Exit Control Loop checks the condition for exit and if given
condition for exit evaluate to true, control will exit from the loop
body else control will enter again into the loop.
Exit control
loop
Do while
loop
 Do while loop
The syntax of while loop is :
How while loop works?
do
{
body of the loop
}
while (testExpression);
The body of do...while loop is executed once. Only then, the
test expression is evaluated.
If the test expression is true, the body of the loop is executed
again and the test expression is evaluated.
This process goes on until the test expression becomes false
If the test expression is false, the loop ends. Flowchart of do while
Example 1
// program to print factorial of number
#include <stdio.h>
void main()
{
int i = 1, num = 0, fact = 1;
printf("Enter a number: ");
scanf("%d", &num);
do
{
fact = fact * i;
i++;
} while (i <= num);
printf("%d", fact);
}
Program :- output :-
Enter a number: 5
120
Nesting of loops is the feature in C that allows the looping of
statements inside another loop. Let's observe an example of nesting
loops in C.
 Nested Loops
Outer_loop
{
Inner_loop
{
// inner loop statements.
}
// outer loop statements.
}
Syntax of Nested loop
NOTE :- Outer loop and Inner loop are the valid loops that can be a 'for' loop,
'while' loop or 'do-while' loop
for (initialization; condition; update)
{
for(initialization; condition; update)
{
// inner loop statements.
}
// outer loop statements.
}
Nested for loop
Nested do. While loop
do
{
do
{
// inner loop statements.
}while(condition);
// outer loop statements.
}while(condition);
syntax :
syntax :
while(condition)
{
while(condition)
{
// inner loop statements.
}
// outer loop statements.
}
Nested while loop
syntax :
Thank you..

More Related Content

What's hot

Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loopsbsdeol28
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c languagesneha2494
 
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
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in CJeya Lakshmi
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming LanguageMahantesh Devoor
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statementsrajshreemuthiah
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
 
Nested loops
Nested loopsNested loops
Nested loopsNeeru Mittal
 
Loop c++
Loop c++Loop c++
Loop c++Mood Mood
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements Tarun Sharma
 
Working of while loop
Working of while loopWorking of while loop
Working of while loopNeeru Mittal
 

What's hot (19)

Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 
Looping
LoopingLooping
Looping
 
Loops in c
Loops in cLoops in c
Loops in c
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
 
Loops in c
Loops in cLoops in c
Loops in c
 
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
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
itretion.docx
itretion.docxitretion.docx
itretion.docx
 
Looping in C
Looping in CLooping in C
Looping in C
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Nested loops
Nested loopsNested loops
Nested loops
 
Loop control in c++
Loop control in c++Loop control in c++
Loop control in c++
 
Iteration
IterationIteration
Iteration
 
Loop c++
Loop c++Loop c++
Loop c++
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Working of while loop
Working of while loopWorking of while loop
Working of while loop
 
Control statements
Control statementsControl statements
Control statements
 

Similar to Loops in c

3. Flow Controls in C (Part II).pdf
3. Flow Controls in C (Part II).pdf3. Flow Controls in C (Part II).pdf
3. Flow Controls in C (Part II).pdfsantosh147365
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02Suhail Akraam
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while LoopJayBhavsar68
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop kapil078
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Shipra Swati
 
Workbook_2_Problem_Solving_and_programming.pdf
Workbook_2_Problem_Solving_and_programming.pdfWorkbook_2_Problem_Solving_and_programming.pdf
Workbook_2_Problem_Solving_and_programming.pdfDrDineshenScientist
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitionsaltwirqi
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetitionHattori Sidek
 
Loops in c language
Loops in c languageLoops in c language
Loops in c languageTanmay Modi
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in CSowmya Jyothi
 
Chapter 13.1.5
Chapter 13.1.5Chapter 13.1.5
Chapter 13.1.5patcha535
 
Control structure of c
Control structure of cControl structure of c
Control structure of cKomal Kotak
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control StructureSokngim Sa
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops Hemantha Kulathilake
 
loops and iteration.docx
loops and iteration.docxloops and iteration.docx
loops and iteration.docxJavvajiVenkat
 

Similar to Loops in c (20)

3. Flow Controls in C (Part II).pdf
3. Flow Controls in C (Part II).pdf3. Flow Controls in C (Part II).pdf
3. Flow Controls in C (Part II).pdf
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while Loop
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
Workbook_2_Problem_Solving_and_programming.pdf
Workbook_2_Problem_Solving_and_programming.pdfWorkbook_2_Problem_Solving_and_programming.pdf
Workbook_2_Problem_Solving_and_programming.pdf
 
Loops c++
Loops c++Loops c++
Loops c++
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitions
 
175035-cse LAB-04
175035-cse LAB-04 175035-cse LAB-04
175035-cse LAB-04
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Looping
LoopingLooping
Looping
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
 
Chapter 13.1.5
Chapter 13.1.5Chapter 13.1.5
Chapter 13.1.5
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
 
loops and iteration.docx
loops and iteration.docxloops and iteration.docx
loops and iteration.docx
 

Recently uploaded

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...masabamasaba
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 

Recently uploaded (20)

%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 

Loops in c

  • 1. Deogiri college, Aurangabad Topic : Loops in c Subject : Programming in c Class : BCA(1st yr. ) By : shubham Narayan pandav
  • 2. There are mainly two types of loops: loops Entry control loop For loop While loop Exit control loop Do while
  • 3. Entry control loop  An entry control loop checks the condition at the time of entry and if condition or expression becomes true then control transfers into the body of the loop. Entry control loop For loop while loop
  • 4.  for Loop :- The syntax of for loop is : for (initializationStatement; testExpression; updateStatement) { // body of loop } The initialization statement is executed only once. Then, the test expression is evaluated. If the test expression is evaluated to false, the for loop is terminated. If the test expression is evaluated to true, statement inside the body of for loop are executed and the update expression is updated This process goes on until the test expression become false. How for loop works? Flowchart of for loop
  • 5. 1 2 3 4 5 6 7 8 9 10 Example 1 output :- Program :- Example 2 // Print numbers from 10 to 1 #include <stdio.h> void main() { int i; for (i = 10; i >=1; i--) { printf("%d ", i); } } // end of main 10 9 8 7 6 5 4 3 2 1 output :- // Print numbers from 1 to 10 #include <stdio.h> void main() { int i; for (i = 1; i <= 10; i++) { printf("%d ", i); } } // end of main
  • 6.  While loop The syntax of while loop is : How while loop works? while (testExpression) { // body of the loop }  if the expression Is true, statements inside the body of while loop are executed. Then, the test expression is evaluated again.  The process of goes on until the expression is evaluated to false.  If the expression is false, the loop terminates(Ends). Flowchart of while loop
  • 7. // program to print table #include <stdio.h> void main() { int i = 1, number; printf("Enter a number : "); scanf("%d", &number); while (i <= 10) { printf("n%d * %d = %d",i,number,i*number); i++; } } 1 * 8 = 8 2 * 8 = 16 3 * 8 = 24 4 * 8 = 32 5 * 8 = 40 6 * 8 = 48 7 * 8 = 56 8 * 8 = 64 9 * 8 = 72 10 * 8 = 80 Program :- output :- Enter a number : 8 Example 1
  • 8. Exit control loop  An Exit Control Loop checks the condition for exit and if given condition for exit evaluate to true, control will exit from the loop body else control will enter again into the loop. Exit control loop Do while loop
  • 9.  Do while loop The syntax of while loop is : How while loop works? do { body of the loop } while (testExpression); The body of do...while loop is executed once. Only then, the test expression is evaluated. If the test expression is true, the body of the loop is executed again and the test expression is evaluated. This process goes on until the test expression becomes false If the test expression is false, the loop ends. Flowchart of do while
  • 10. Example 1 // program to print factorial of number #include <stdio.h> void main() { int i = 1, num = 0, fact = 1; printf("Enter a number: "); scanf("%d", &num); do { fact = fact * i; i++; } while (i <= num); printf("%d", fact); } Program :- output :- Enter a number: 5 120
  • 11. Nesting of loops is the feature in C that allows the looping of statements inside another loop. Let's observe an example of nesting loops in C.  Nested Loops Outer_loop { Inner_loop { // inner loop statements. } // outer loop statements. } Syntax of Nested loop NOTE :- Outer loop and Inner loop are the valid loops that can be a 'for' loop, 'while' loop or 'do-while' loop
  • 12. for (initialization; condition; update) { for(initialization; condition; update) { // inner loop statements. } // outer loop statements. } Nested for loop Nested do. While loop do { do { // inner loop statements. }while(condition); // outer loop statements. }while(condition); syntax : syntax : while(condition) { while(condition) { // inner loop statements. } // outer loop statements. } Nested while loop syntax :