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 (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
 
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

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 

Recently uploaded (20)

Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 

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 :