SlideShare a Scribd company logo
6
Most read
10
Most read
17
Most read
LOOPS
PRESENTATION
LOOPS :
 WHY DO WE NEED LOOPS ???
 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
LOOPS :
 TYPES OF LOOPS :
 WHILE LOOP
 FOR LOOP
 DO-WHILE LOOP
 NESTED LOOP
 LETS HAVE A CLOSER LOOK
LOOPS => WHILE LOOP
A while loop statement repeatedly executes a target
statement as long as a given condition is true.
Syntax:
The syntax of a while loop in C is:
while(condition)
{
statement(s);
}
LOOPS => WHILE LOOP
 Here, statement(s) may be a single statement or a
block of statements. The condition may be any
expression, and true is any non-zero value. The
loop iterates while the condition is true.
 When the condition becomes false, program control
passes to the line immediately following the loop
LOOPS => WHILE LOOP
FLOW DAIGRAM
LOOPS => WHILE LOOP
 EXAMPLE :
#include<stdlib.h>
int main ()
{
// Local variable declaration:
int a = 10;
// while loop execution
while( a < 20 )
{
printf(“value of a:%d /n”, a);
a++;
}
getch()
}
LOOPS => WHILE LOOP
 When the above code is compiled and executed, it
produces the following result:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
LOOPS :
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:
The syntax of a for loop in C is:
for ( init; condition; increment )
{
statement(s);
}
LOOPS => 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.
LOOPS => 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.
LOOPS=> FOR LOOP
 Flow Diagram:
LOOPS => FOR LOOP
Example:
#include<stdlib.h>
int main ()
{ // for loop execution
for( int a = 10; a < 20; a = a + 1 )
{
printf("value of a: %d /n”, a);
}
getch();
}
LOOPS => FOR LOOP
 When the above code is compiled and executed, it
produces the following result:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
LOOPS :
 DO-WHILE LOOP:
 Unlike for and while loops, which test the loop
condition at the top of the loop, the do...while loop
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.
LOOPS => DO-WHILE LOOP
Syntax:
The syntax of a do...while loop in C is:
do
{
statement(s);
}
while( condition );
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.
LOOPS => DO-WHILE LOOP
 Flow Diagram:
LOOPS => DO-WHILE LOOP
 Example:
#include<stdlib.h>
int main ()
{ // Local variable declaration:
int a = 10;
// do loop execution
do
{
printf( "value of a: %dn “ ,a);
a = a + 1;
} while( a < 20 );
getch();
}
LOOPS => DO-WHILE LOOP
 When the above code is compiled and executed, it
produces the following result:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
value of a: 16
value of a: 17
value of a: 18
value of a: 19
LOOPS :
 NESTED LOOPS :
 A loop can be nested inside of another loop.
 Syntax:
The syntax for a nested for loop statement in C is as follows:
for ( init; condition; increment )
{
for ( init; condition; increment )
{
statement(s);
}
statement(s);
// you can put more statements.
}
LOOPS => NESTED LOOP
 EXAMPLE :
#include<stdlib.h>
int main ()
{
int a=1,b;
while(a<=3)
{
for(b=1;b<=3;b++)
{
printf("a = %d , b = %dn",a,b);
}
printf("n");
a++;
}
system("pause");
}
LOOPS => NESTED LOOP
 When the above code is compiled and executed, it
produces the following result:
a = 1 , b = 1
a = 1 , b = 2
a = 1 , b = 3
a = 2 , b = 1
a = 2 , b = 2
a = 2 , b = 3
a = 3 , b = 1
a = 3 , b = 2
a = 3 , b = 3

More Related Content

PPTX
Java data types
AbhishekMondal42
 
PDF
Unit II chapter 4 Loops in C
Sowmya Jyothi
 
PPTX
Java loops for, while and do...while
Jayfee Ramos
 
PPTX
Presentation on nesting of loops
bsdeol28
 
PPTX
Functions in c language
tanmaymodi4
 
PPTX
Rules for Variable Declaration
uniprint
 
PPT
Operators in C++
Sachin Sharma
 
PPTX
C Programming: Structure and Union
Selvaraj Seerangan
 
Java data types
AbhishekMondal42
 
Unit II chapter 4 Loops in C
Sowmya Jyothi
 
Java loops for, while and do...while
Jayfee Ramos
 
Presentation on nesting of loops
bsdeol28
 
Functions in c language
tanmaymodi4
 
Rules for Variable Declaration
uniprint
 
Operators in C++
Sachin Sharma
 
C Programming: Structure and Union
Selvaraj Seerangan
 

What's hot (20)

PDF
Estructura de control repetitiva
villandri pachco
 
PPTX
C++ decision making
Zohaib Ahmed
 
PPTX
Variables in C and C++ Language
Way2itech
 
PPT
While loop
Feras_83
 
PPTX
Looping statements in C
Jeya Lakshmi
 
PPTX
Preprocessor directives in c language
tanmaymodi4
 
PPTX
Pointers in c++
sai tarlekar
 
PPTX
POP vs OOP Introduction
Hashni T
 
PPT
Union In language C
Ravi Singh
 
PPTX
C Structures and Unions
Dhrumil Patel
 
PPTX
INLINE FUNCTION IN C++
Vraj Patel
 
PPTX
Loops in C
Kamal Acharya
 
PPSX
Data Types & Variables in JAVA
Ankita Totala
 
PPT
File handling-c
CGC Technical campus,Mohali
 
PPSX
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
PPT
PHP - Introduction to File Handling with PHP
Vibrant Technologies & Computers
 
PPTX
C functions
University of Potsdam
 
PPTX
Union in C programming
Kamal Acharya
 
Estructura de control repetitiva
villandri pachco
 
C++ decision making
Zohaib Ahmed
 
Variables in C and C++ Language
Way2itech
 
While loop
Feras_83
 
Looping statements in C
Jeya Lakshmi
 
Preprocessor directives in c language
tanmaymodi4
 
Pointers in c++
sai tarlekar
 
POP vs OOP Introduction
Hashni T
 
Union In language C
Ravi Singh
 
C Structures and Unions
Dhrumil Patel
 
INLINE FUNCTION IN C++
Vraj Patel
 
Loops in C
Kamal Acharya
 
Data Types & Variables in JAVA
Ankita Totala
 
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
PHP - Introduction to File Handling with PHP
Vibrant Technologies & Computers
 
Union in C programming
Kamal Acharya
 
Ad

Similar to loops in C ppt.pdf (20)

PPTX
Loops Basics
Mushiii
 
PPTX
Loops in c
RekhaBudhwar
 
PDF
Loop and while Loop
JayBhavsar68
 
PPTX
Cse lecture-7-c loop
FarshidKhan
 
PDF
LOOP STATEMENTS AND TYPES OF LOOP IN C LANGUAGE BY RIZWAN
MD RIZWAN MOLLA
 
DOCX
Looping statements
Chukka Nikhil Chakravarthy
 
PPTX
The Loops
Krishma Parekh
 
PPTX
Decision Making and Looping
Munazza-Mah-Jabeen
 
DOCX
loops and iteration.docx
JavvajiVenkat
 
PDF
cpu.pdf
RAJCHATTERJEE24
 
PPTX
While , For , Do-While Loop
Abhishek Choksi
 
PPTX
Loop (Computer programming and utilization)
Digvijaysinh Gohil
 
PPTX
Loops in C programming language/ Types of loops
Mahendra Dheer
 
PPTX
Types of loops in c language
sneha2494
 
PPTX
C Programming Language Part 6
Rumman Ansari
 
PPTX
Loops
SAMYAKKHADSE
 
PPTX
C Programming: Looping Statements in C Pgm
Navya Francis
 
DOCX
Programming Fundamentals lecture 8
REHAN IJAZ
 
PDF
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Priyom Majumder
 
PDF
ICP - Lecture 9
hassaanciit
 
Loops Basics
Mushiii
 
Loops in c
RekhaBudhwar
 
Loop and while Loop
JayBhavsar68
 
Cse lecture-7-c loop
FarshidKhan
 
LOOP STATEMENTS AND TYPES OF LOOP IN C LANGUAGE BY RIZWAN
MD RIZWAN MOLLA
 
Looping statements
Chukka Nikhil Chakravarthy
 
The Loops
Krishma Parekh
 
Decision Making and Looping
Munazza-Mah-Jabeen
 
loops and iteration.docx
JavvajiVenkat
 
While , For , Do-While Loop
Abhishek Choksi
 
Loop (Computer programming and utilization)
Digvijaysinh Gohil
 
Loops in C programming language/ Types of loops
Mahendra Dheer
 
Types of loops in c language
sneha2494
 
C Programming Language Part 6
Rumman Ansari
 
C Programming: Looping Statements in C Pgm
Navya Francis
 
Programming Fundamentals lecture 8
REHAN IJAZ
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Priyom Majumder
 
ICP - Lecture 9
hassaanciit
 
Ad

More from DrSamsonChepuri1 (9)

PPT
INTRUSION_ DETECTION_AND_PREVENTION _SYSTEM
DrSamsonChepuri1
 
PPTX
CYBER SECURITY :Cyber Law – The Legal Perspectives
DrSamsonChepuri1
 
PPT
remoteing.ppt
DrSamsonChepuri1
 
PPT
e-comm new2.ppt
DrSamsonChepuri1
 
PPT
BASIC LAWS OF CONSUPTION AND DEMAND ANALYSIS.ppt
DrSamsonChepuri1
 
PPT
lect01.ppt
DrSamsonChepuri1
 
PPT
how-to-write-an-abstract_medical.ppt
DrSamsonChepuri1
 
PPT
research_paper_powerpoint.ppt
DrSamsonChepuri1
 
PPT
ASN_ ppt.ppt
DrSamsonChepuri1
 
INTRUSION_ DETECTION_AND_PREVENTION _SYSTEM
DrSamsonChepuri1
 
CYBER SECURITY :Cyber Law – The Legal Perspectives
DrSamsonChepuri1
 
remoteing.ppt
DrSamsonChepuri1
 
e-comm new2.ppt
DrSamsonChepuri1
 
BASIC LAWS OF CONSUPTION AND DEMAND ANALYSIS.ppt
DrSamsonChepuri1
 
lect01.ppt
DrSamsonChepuri1
 
how-to-write-an-abstract_medical.ppt
DrSamsonChepuri1
 
research_paper_powerpoint.ppt
DrSamsonChepuri1
 
ASN_ ppt.ppt
DrSamsonChepuri1
 

Recently uploaded (20)

PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PPTX
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PPT
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
PDF
Zero Carbon Building Performance standard
BassemOsman1
 
PDF
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
PDF
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
PPTX
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
PDF
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
PDF
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
PPTX
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PDF
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPTX
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 
Inventory management chapter in automation and robotics.
atisht0104
 
MSME 4.0 Template idea hackathon pdf to understand
alaudeenaarish
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
2025 Laurence Sigler - Advancing Decision Support. Content Management Ecommer...
Francisco Javier Mora Serrano
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
1. SYSTEMS, ROLES, AND DEVELOPMENT METHODOLOGIES.ppt
zilow058
 
Zero Carbon Building Performance standard
BassemOsman1
 
AI-Driven IoT-Enabled UAV Inspection Framework for Predictive Maintenance and...
ijcncjournal019
 
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
STUDY OF NOVEL CHANNEL MATERIALS USING III-V COMPOUNDS WITH VARIOUS GATE DIEL...
ijoejnl
 
The Effect of Artifact Removal from EEG Signals on the Detection of Epileptic...
Partho Prosad
 
IoT_Smart_Agriculture_Presentations.pptx
poojakumari696707
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
LEAP-1B presedntation xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
hatem173148
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
22PCOAM21 Session 2 Understanding Data Source.pptx
Guru Nanak Technical Institutions
 

loops in C ppt.pdf

  • 2. LOOPS :  WHY DO WE NEED LOOPS ???  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
  • 3. LOOPS :  TYPES OF LOOPS :  WHILE LOOP  FOR LOOP  DO-WHILE LOOP  NESTED LOOP  LETS HAVE A CLOSER LOOK
  • 4. LOOPS => WHILE LOOP A while loop statement repeatedly executes a target statement as long as a given condition is true. Syntax: The syntax of a while loop in C is: while(condition) { statement(s); }
  • 5. LOOPS => WHILE LOOP  Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any non-zero value. The loop iterates while the condition is true.  When the condition becomes false, program control passes to the line immediately following the loop
  • 6. LOOPS => WHILE LOOP FLOW DAIGRAM
  • 7. LOOPS => WHILE LOOP  EXAMPLE : #include<stdlib.h> int main () { // Local variable declaration: int a = 10; // while loop execution while( a < 20 ) { printf(“value of a:%d /n”, a); a++; } getch() }
  • 8. LOOPS => WHILE LOOP  When the above code is compiled and executed, it produces the following result: value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19
  • 9. LOOPS : 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: The syntax of a for loop in C is: for ( init; condition; increment ) { statement(s); }
  • 10. LOOPS => 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.
  • 11. LOOPS => 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.
  • 12. LOOPS=> FOR LOOP  Flow Diagram:
  • 13. LOOPS => FOR LOOP Example: #include<stdlib.h> int main () { // for loop execution for( int a = 10; a < 20; a = a + 1 ) { printf("value of a: %d /n”, a); } getch(); }
  • 14. LOOPS => FOR LOOP  When the above code is compiled and executed, it produces the following result: value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19
  • 15. LOOPS :  DO-WHILE LOOP:  Unlike for and while loops, which test the loop condition at the top of the loop, the do...while loop 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.
  • 16. LOOPS => DO-WHILE LOOP Syntax: The syntax of a do...while loop in C is: do { statement(s); } while( condition ); 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.
  • 17. LOOPS => DO-WHILE LOOP  Flow Diagram:
  • 18. LOOPS => DO-WHILE LOOP  Example: #include<stdlib.h> int main () { // Local variable declaration: int a = 10; // do loop execution do { printf( "value of a: %dn “ ,a); a = a + 1; } while( a < 20 ); getch(); }
  • 19. LOOPS => DO-WHILE LOOP  When the above code is compiled and executed, it produces the following result: value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15 value of a: 16 value of a: 17 value of a: 18 value of a: 19
  • 20. LOOPS :  NESTED LOOPS :  A loop can be nested inside of another loop.  Syntax: The syntax for a nested for loop statement in C is as follows: for ( init; condition; increment ) { for ( init; condition; increment ) { statement(s); } statement(s); // you can put more statements. }
  • 21. LOOPS => NESTED LOOP  EXAMPLE : #include<stdlib.h> int main () { int a=1,b; while(a<=3) { for(b=1;b<=3;b++) { printf("a = %d , b = %dn",a,b); } printf("n"); a++; } system("pause"); }
  • 22. LOOPS => NESTED LOOP  When the above code is compiled and executed, it produces the following result: a = 1 , b = 1 a = 1 , b = 2 a = 1 , b = 3 a = 2 , b = 1 a = 2 , b = 2 a = 2 , b = 3 a = 3 , b = 1 a = 3 , b = 2 a = 3 , b = 3