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

PPTX
Looping Statement And Flow Chart
PPT
For Loop
PPT
Different loops in C
PPT
PPTX
C Language - Switch and For Loop
DOCX
Looping statements
PPTX
Loops in c language
PDF
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Looping Statement And Flow Chart
For Loop
Different loops in C
C Language - Switch and For Loop
Looping statements
Loops in c language
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop

What's hot (19)

PPTX
Presentation on nesting of loops
PPTX
Loops in c
PPTX
Types of loops in c language
PPSX
C lecture 4 nested loops and jumping statements slideshare
PPTX
Looping statements in C
DOCX
itretion.docx
PPT
Looping in C
PPTX
Loops in C Programming Language
PPTX
Control and conditional statements
PPTX
Decision statements in c language
PPTX
Nested loops
PPTX
Loop control in c++
PPT
Iteration
PPTX
Loop c++
PPTX
Control Flow Statements
PPTX
Working of while loop
PDF
Control statements
Presentation on nesting of loops
Loops in c
Types of loops in c language
C lecture 4 nested loops and jumping statements slideshare
Looping statements in C
itretion.docx
Looping in C
Loops in C Programming Language
Control and conditional statements
Decision statements in c language
Nested loops
Loop control in c++
Iteration
Loop c++
Control Flow Statements
Working of while loop
Control statements
Ad

Similar to Loops in c (20)

PDF
3. Flow Controls in C (Part II).pdf
PDF
Programming fundamental 02
PDF
Loop and while Loop
PPT
12 lec 12 loop
PDF
Fundamental of Information Technology - UNIT 8
PDF
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PDF
Workbook_2_Problem_Solving_and_programming.pdf
PPTX
Loops c++
DOC
Slide07 repetitions
PDF
175035-cse LAB-04
PPTX
Ch6 Loops
PPT
Ch3 repetition
PPTX
Loops in c language
PDF
Unit II chapter 4 Loops in C
PDF
Chapter 13.1.5
PPTX
Control structure of c
PDF
04-Looping( For , while and do while looping) .pdf
PPTX
Control Structures in C
PPTX
C Programming: Control Structure
3. Flow Controls in C (Part II).pdf
Programming fundamental 02
Loop and while Loop
12 lec 12 loop
Fundamental of Information Technology - UNIT 8
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
Workbook_2_Problem_Solving_and_programming.pdf
Loops c++
Slide07 repetitions
175035-cse LAB-04
Ch6 Loops
Ch3 repetition
Loops in c language
Unit II chapter 4 Loops in C
Chapter 13.1.5
Control structure of c
04-Looping( For , while and do while looping) .pdf
Control Structures in C
C Programming: Control Structure
Ad

Recently uploaded (20)

PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PDF
17 Powerful Integrations Your Next-Gen MLM Software Needs
PPTX
Monitoring Stack: Grafana, Loki & Promtail
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
iTop VPN Crack Latest Version Full Key 2025
PDF
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Website Design Services for Small Businesses.pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
Reimagine Home Health with the Power of Agentic AI​
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
17 Powerful Integrations Your Next-Gen MLM Software Needs
Monitoring Stack: Grafana, Loki & Promtail
Navsoft: AI-Powered Business Solutions & Custom Software Development
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Odoo Companies in India – Driving Business Transformation.pdf
Salesforce Agentforce AI Implementation.pdf
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
iTop VPN Crack Latest Version Full Key 2025
iTop VPN 6.5.0 Crack + License Key 2025 (Premium Version)
Computer Software and OS of computer science of grade 11.pptx
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Website Design Services for Small Businesses.pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Weekly report ppt - harsh dattuprasad patel.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 :