SlideShare a Scribd company logo
Gagan Deep 
Rozy Computech Services 
3rd Gate, K.U., Kurukshetra-136119 
M- 9416011599 
Email – rozygag@yahoo.com
Looping 
Suppose we want to display hello on output screen five 
times in five different lines. 
We might think of writing either five printf statements or 
one printf statement consisting of constant “hellon” five 
times. 
What if we want to display hello 500 times? 
Should we write 500 printf statement or equivalent ? 
Obviously not. 
It means that we need some programming facility to 
repeat certain works. 
Such facility in Programming Languages is available in 
the form Looping Statements.
Looping 
Loops are used to repeat something. 
Repetition of block of code. 
If program requires that group of instructions be executed 
repeatedly is known as looping. 
Looping is of two types 
Conditional 
Unconditional 
Conditional Looping: Computation continues indefinitely 
until the logical condition is true. 
Unconditional Looping : The number of repetition known 
in advance or repetition is infinite.
C lecture 3 control statements slideshare
Types of Loops 
Conditional Loops 
While Loop – Pre Condition Loop – Entry Time 
Conditional Loop 
Do-While Loop – Post Condition Loop – Exit Time 
Conditional Loop 
Unconditional Loop 
For Loop – Counted Loops 
Uncounted Loop – Infinite loop 
Uncounted Loop –infinite loop controlled by 
control statements.
while Statement 
The while statement is used to carry out looping 
operations, in which a group of statement is executed 
repeatedly, until some condition has been satisfied. 
The general form of statement is 
while (test expression) 
statement to be executed; 
or 
while (test expression) 
{ statements to be executed }
Program 1-4 First 10 Natural Numbers 
#include <stdio.h> 
void main() 
{ int i=0; 
while(i<=9) // i<10 
printf(“%d”, i++); 
}/*here we can’t use ++i – that gives 
different result*/ 
//only a statement 
#include <stdio.h> 
void main() 
{ int i=0; 
while(i<=9) // i<10 
{ printf(“%dn”, i); 
i++; }//compound statement 
} //we also can use ++i 
#include <stdio.h> 
void main() 
{ int i=10; 
while(i<=9) // i<10 
{ printf(“%d”, i); 
i++; } 
// doesn’t work body of loop 
} 
#include <stdio.h> 
void main() 
{ int i=9; 
while(i>=0) // i>-1 
{ printf(“%d”, i); 
i--; } //--i 
}//decrement – decreasing order
do…..while Statement 
When a loop is constructed using the while 
statement, the test for continuation of the loop 
carried out at the beginning of each pass. 
Sometimes, however it is desirable to have a loop with 
the test for continuation at the end the end of each 
pass. This can be accomplished by do..while 
statement. The general form of statement is 
do Statement; //single statement 
while (expression); or 
do 
{ statements to be executed } 
while (expression);
Program 5-8 First 10 Natural Numbers 
#include <stdio.h> 
void main() 
{ int i=0; 
do 
printf(“%d”, i++); 
while(i<=9); } 
#include <stdio.h> 
void main() 
{ int i=0; 
do 
{printf(“%dn”, i); 
i++; } 
while(i<=9) ; } 
#include <stdio.h> 
void main() 
{ int i=10; 
do //first execute then check 
{ printf(“%d”, i); 
i++; } while(i<=9) ; } 
// prints 10(execute one time) 
#include <stdio.h> 
void main() 
{ int i=9; 
do{ printf(“%d”, i); 
i--; } 
while(i>=0) ; }
for Statement 
The for statement is the third and perhaps the most 
commonly used looping statement in C. 
This statement includes an expression 
that specifies an initial value for an index, 
another expression 
that determines whether or not the loop is continued, 
and a third expression 
that allows the index to be modified at the end of 
each pass. 
The general form of statement is 
for (expr1; expr2; expr3) 
statement; or { statements }
Print 1 to 10 Program 9-12 
#include<stdio.h> 
#include<stdio.h> 
void main() 
void main() 
{int i; 
{ 
for(i=1;i<=10;i++) 
for(int i=1;i<=10;++i) 
printf(“%d”,i); } 
printf(“%d”,i); } 
#include<stdio.h> 
void main() 
{ 
for(int i=1;i<=10;i=i+1) 
printf(“%d”,i); 
} 
#include<stdio.h> 
void main() 
{int i=1; 
for( ; i<=10; ) 
{ printf(“%d”,i); 
i++ ; } 
}//you can also use ++i
Program 13-16 
#include<stdio.h> 
void main() 
{for(int i=0;i<5;i++) 
{ } 
} // i goes to 5 only 
#include<stdio.h> 
void main() 
{ 
for(i=0;i<5;i++); 
} // i goes to 5 only 
Comma Operator 
#include<stdio.h> 
void main() 
{ 
for(i=0,j=0;i<5;i++, j++) { 
statement1; statement2; 
statement3; } 
#include<stdio.h> 
void main() 
{int i = 0; 
for( ; ;) 
{ statements; 
if(breaking condition) 
break; i++; }
Program 17-18 
Reverse Number 
#include<stdio.h> 
void main() 
{n, r, rn=0; 
scanf(“%d”, &n); 
while (n!=0) { 
r=n%10; n=n/10 ; 
rn=rn*10+r; } 
printf(“Reverese Number 
=%d”, rn); 
} 
Palindrome Number 
#include<stdio.h> 
void main() 
{n, r, T, rn=0; 
scanf(“%d”, &n); T=n; 
while (T!=0) { 
r=T%10; T=T/10 ; 
rn=rn*10+r; } 
if (rn==n) 
printf(“Palindrome Number); 
else 
printf(“Non-Palindrome 
Number); 
}
Program 19 
Prime Number 
#include<stdio.h> 
void main() 
{n, i; 
scanf(“%d”, &n); 
while (n % i != 0) 
i++; 
if (n==i) 
printf(“%d is prime”, n); 
}
If you have any queries you can 
contact me at : 
rozygag@yahoo.com

More Related Content

What's hot (20)

PPTX
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Maulik Borsaniya
 
PDF
Chapter 2 : Balagurusamy_ Programming ANsI in C
BUBT
 
PPTX
C if else
Ritwik Das
 
PDF
durga python full.pdf
ssuser476810
 
PPTX
While , For , Do-While Loop
Abhishek Choksi
 
PPT
16717 functions in C++
LPU
 
PPTX
PYTHON FEATURES.pptx
MaheShiva
 
PPT
Control structures in C++ Programming Language
Ahmad Idrees
 
PPT
Unit 1 python (2021 r)
praveena p
 
PDF
Object oriented programming c++
Ankur Pandey
 
PPTX
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 
PPTX
Encapsulation C++
Hashim Hashim
 
PPTX
Presentation on nesting of loops
bsdeol28
 
PPT
C++ Function
Hajar
 
PDF
C Programming Storage classes, Recursion
Sreedhar Chowdam
 
PPTX
Logical and Conditional Operator In C language
Abdul Rehman
 
PDF
Programming Fundamentals Functions in C and types
imtiazalijoono
 
PPTX
C tokens
Manu1325
 
PPTX
User defined functions in C
Harendra Singh
 
Chapter 1 - INTRODUCTION TO PYTHON -MAULIK BORSANIYA
Maulik Borsaniya
 
Chapter 2 : Balagurusamy_ Programming ANsI in C
BUBT
 
C if else
Ritwik Das
 
durga python full.pdf
ssuser476810
 
While , For , Do-While Loop
Abhishek Choksi
 
16717 functions in C++
LPU
 
PYTHON FEATURES.pptx
MaheShiva
 
Control structures in C++ Programming Language
Ahmad Idrees
 
Unit 1 python (2021 r)
praveena p
 
Object oriented programming c++
Ankur Pandey
 
Interface in java ,multiple inheritance in java, interface implementation
HoneyChintal
 
Encapsulation C++
Hashim Hashim
 
Presentation on nesting of loops
bsdeol28
 
C++ Function
Hajar
 
C Programming Storage classes, Recursion
Sreedhar Chowdam
 
Logical and Conditional Operator In C language
Abdul Rehman
 
Programming Fundamentals Functions in C and types
imtiazalijoono
 
C tokens
Manu1325
 
User defined functions in C
Harendra Singh
 

Viewers also liked (16)

PPTX
Introduction to Visual Basic (Week 2)
Don Bosco School Manila
 
PDF
Vbasic
Gowri Shankar
 
PPTX
Steps to migrate vb6 application to vb dotnet
Debabrata Adhya
 
KEY
.Net branching and flow control
LearnNowOnline
 
PPTX
VB Function and procedure
pragya ratan
 
PPTX
Vb decision making statements
pragya ratan
 
PPSX
Control Structures in Visual Basic
Tushar Jain
 
PPTX
C++ loop
Khelan Ameen
 
PPT
visual basic for the beginner
Salim M
 
PPTX
Loops c++
Shivani Singh
 
PPTX
Decision statements in vb.net
ilakkiya
 
PPTX
Looping statement in vb.net
ilakkiya
 
PPT
Looping statements in Java
Jin Castor
 
PDF
Control statements
Kanwalpreet Kaur
 
PPT
Visual basic ppt for tutorials computer
simran153
 
PPTX
Slideshare ppt
Mandy Suzanne
 
Introduction to Visual Basic (Week 2)
Don Bosco School Manila
 
Steps to migrate vb6 application to vb dotnet
Debabrata Adhya
 
.Net branching and flow control
LearnNowOnline
 
VB Function and procedure
pragya ratan
 
Vb decision making statements
pragya ratan
 
Control Structures in Visual Basic
Tushar Jain
 
C++ loop
Khelan Ameen
 
visual basic for the beginner
Salim M
 
Loops c++
Shivani Singh
 
Decision statements in vb.net
ilakkiya
 
Looping statement in vb.net
ilakkiya
 
Looping statements in Java
Jin Castor
 
Control statements
Kanwalpreet Kaur
 
Visual basic ppt for tutorials computer
simran153
 
Slideshare ppt
Mandy Suzanne
 
Ad

Similar to C lecture 3 control statements slideshare (20)

PPT
12 lec 12 loop
kapil078
 
PPT
Chapter06.PPT
vamsiKrishnasai3
 
PDF
Workbook_2_Problem_Solving_and_programming.pdf
DrDineshenScientist
 
PPTX
COM1407: Program Control Structures – Repetition and Loops
Hemantha Kulathilake
 
PPT
Lecture 13 Loops1 with C++ programming.PPT
SamahAdel16
 
PPTX
Looping statements.pptx for basic in c language
aryann1217z
 
PPTX
Looping statements c language basics ppt with example
aryann1217z
 
DOC
Slide07 repetitions
altwirqi
 
PDF
04-Looping( For , while and do while looping) .pdf
nithishkumar2867
 
PPTX
Decision Making and Looping
Munazza-Mah-Jabeen
 
PPTX
C Programming: Looping Statements in C Pgm
Navya Francis
 
PDF
Repetition, Basic loop structures, Loop programming techniques
Jason J Pulikkottil
 
PPSX
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
PPT
Week2 ch4 part1edited 2020
Osama Ghandour Geris
 
PPT
Week2 ch4 part1edited 2020
Osama Ghandour Geris
 
DOC
3. control statement
Shankar Gangaju
 
PPT
Control structures repetition
Online
 
12 lec 12 loop
kapil078
 
Chapter06.PPT
vamsiKrishnasai3
 
Workbook_2_Problem_Solving_and_programming.pdf
DrDineshenScientist
 
COM1407: Program Control Structures – Repetition and Loops
Hemantha Kulathilake
 
Lecture 13 Loops1 with C++ programming.PPT
SamahAdel16
 
Looping statements.pptx for basic in c language
aryann1217z
 
Looping statements c language basics ppt with example
aryann1217z
 
Slide07 repetitions
altwirqi
 
04-Looping( For , while and do while looping) .pdf
nithishkumar2867
 
Decision Making and Looping
Munazza-Mah-Jabeen
 
C Programming: Looping Statements in C Pgm
Navya Francis
 
Repetition, Basic loop structures, Loop programming techniques
Jason J Pulikkottil
 
C lecture 4 nested loops and jumping statements slideshare
Gagan Deep
 
Week2 ch4 part1edited 2020
Osama Ghandour Geris
 
Week2 ch4 part1edited 2020
Osama Ghandour Geris
 
3. control statement
Shankar Gangaju
 
Control structures repetition
Online
 
Ad

More from Gagan Deep (19)

PPSX
Number system
Gagan Deep
 
PPSX
Fundamentals of Neural Networks
Gagan Deep
 
PPSX
Artificial Intelligence
Gagan Deep
 
PPSX
Software Project Planning V
Gagan Deep
 
PPSX
Software Project Planning IV
Gagan Deep
 
PPSX
Software Project Planning III
Gagan Deep
 
PPSX
Software Project Planning II
Gagan Deep
 
PPSX
Software Project Planning 1
Gagan Deep
 
PPSX
Software Engineering
Gagan Deep
 
PPSX
C Programming : Arrays
Gagan Deep
 
PPSX
C – A Programming Language- I
Gagan Deep
 
PPSX
System Analysis & Design - 2
Gagan Deep
 
PPSX
System Analysis & Design - I
Gagan Deep
 
PPSX
Information System and MIS
Gagan Deep
 
PPTX
SQL – A Tutorial I
Gagan Deep
 
PPTX
Boolean algebra
Gagan Deep
 
PPTX
Normalization 1
Gagan Deep
 
PPTX
Normalization i i
Gagan Deep
 
PPT
Plsql overview
Gagan Deep
 
Number system
Gagan Deep
 
Fundamentals of Neural Networks
Gagan Deep
 
Artificial Intelligence
Gagan Deep
 
Software Project Planning V
Gagan Deep
 
Software Project Planning IV
Gagan Deep
 
Software Project Planning III
Gagan Deep
 
Software Project Planning II
Gagan Deep
 
Software Project Planning 1
Gagan Deep
 
Software Engineering
Gagan Deep
 
C Programming : Arrays
Gagan Deep
 
C – A Programming Language- I
Gagan Deep
 
System Analysis & Design - 2
Gagan Deep
 
System Analysis & Design - I
Gagan Deep
 
Information System and MIS
Gagan Deep
 
SQL – A Tutorial I
Gagan Deep
 
Boolean algebra
Gagan Deep
 
Normalization 1
Gagan Deep
 
Normalization i i
Gagan Deep
 
Plsql overview
Gagan Deep
 

Recently uploaded (20)

PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PPTX
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
PPTX
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
epi editorial commitee meeting presentation
MIPLM
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PPTX
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
PPTX
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
PPTX
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
How to Create Odoo JS Dialog_Popup in Odoo 18
Celine George
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Android Programming - Basics of Mobile App, App tools and Android Basics
Kavitha P.V
 
TRANSLATIONAL AND ROTATIONAL MOTION.pptx
KIPAIZAGABAWA1
 
Difference between write and update in odoo 18
Celine George
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
epi editorial commitee meeting presentation
MIPLM
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
care of patient with elimination needs.pptx
Rekhanjali Gupta
 
Identifying elements in the story. Arrange the events in the story
geraldineamahido2
 
Introduction to Biochemistry & Cellular Foundations.pptx
marvinnbustamante1
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 

C lecture 3 control statements slideshare

  • 1. Gagan Deep Rozy Computech Services 3rd Gate, K.U., Kurukshetra-136119 M- 9416011599 Email – [email protected]
  • 2. Looping Suppose we want to display hello on output screen five times in five different lines. We might think of writing either five printf statements or one printf statement consisting of constant “hellon” five times. What if we want to display hello 500 times? Should we write 500 printf statement or equivalent ? Obviously not. It means that we need some programming facility to repeat certain works. Such facility in Programming Languages is available in the form Looping Statements.
  • 3. Looping Loops are used to repeat something. Repetition of block of code. If program requires that group of instructions be executed repeatedly is known as looping. Looping is of two types Conditional Unconditional Conditional Looping: Computation continues indefinitely until the logical condition is true. Unconditional Looping : The number of repetition known in advance or repetition is infinite.
  • 5. Types of Loops Conditional Loops While Loop – Pre Condition Loop – Entry Time Conditional Loop Do-While Loop – Post Condition Loop – Exit Time Conditional Loop Unconditional Loop For Loop – Counted Loops Uncounted Loop – Infinite loop Uncounted Loop –infinite loop controlled by control statements.
  • 6. while Statement The while statement is used to carry out looping operations, in which a group of statement is executed repeatedly, until some condition has been satisfied. The general form of statement is while (test expression) statement to be executed; or while (test expression) { statements to be executed }
  • 7. Program 1-4 First 10 Natural Numbers #include <stdio.h> void main() { int i=0; while(i<=9) // i<10 printf(“%d”, i++); }/*here we can’t use ++i – that gives different result*/ //only a statement #include <stdio.h> void main() { int i=0; while(i<=9) // i<10 { printf(“%dn”, i); i++; }//compound statement } //we also can use ++i #include <stdio.h> void main() { int i=10; while(i<=9) // i<10 { printf(“%d”, i); i++; } // doesn’t work body of loop } #include <stdio.h> void main() { int i=9; while(i>=0) // i>-1 { printf(“%d”, i); i--; } //--i }//decrement – decreasing order
  • 8. do…..while Statement When a loop is constructed using the while statement, the test for continuation of the loop carried out at the beginning of each pass. Sometimes, however it is desirable to have a loop with the test for continuation at the end the end of each pass. This can be accomplished by do..while statement. The general form of statement is do Statement; //single statement while (expression); or do { statements to be executed } while (expression);
  • 9. Program 5-8 First 10 Natural Numbers #include <stdio.h> void main() { int i=0; do printf(“%d”, i++); while(i<=9); } #include <stdio.h> void main() { int i=0; do {printf(“%dn”, i); i++; } while(i<=9) ; } #include <stdio.h> void main() { int i=10; do //first execute then check { printf(“%d”, i); i++; } while(i<=9) ; } // prints 10(execute one time) #include <stdio.h> void main() { int i=9; do{ printf(“%d”, i); i--; } while(i>=0) ; }
  • 10. for Statement The for statement is the third and perhaps the most commonly used looping statement in C. This statement includes an expression that specifies an initial value for an index, another expression that determines whether or not the loop is continued, and a third expression that allows the index to be modified at the end of each pass. The general form of statement is for (expr1; expr2; expr3) statement; or { statements }
  • 11. Print 1 to 10 Program 9-12 #include<stdio.h> #include<stdio.h> void main() void main() {int i; { for(i=1;i<=10;i++) for(int i=1;i<=10;++i) printf(“%d”,i); } printf(“%d”,i); } #include<stdio.h> void main() { for(int i=1;i<=10;i=i+1) printf(“%d”,i); } #include<stdio.h> void main() {int i=1; for( ; i<=10; ) { printf(“%d”,i); i++ ; } }//you can also use ++i
  • 12. Program 13-16 #include<stdio.h> void main() {for(int i=0;i<5;i++) { } } // i goes to 5 only #include<stdio.h> void main() { for(i=0;i<5;i++); } // i goes to 5 only Comma Operator #include<stdio.h> void main() { for(i=0,j=0;i<5;i++, j++) { statement1; statement2; statement3; } #include<stdio.h> void main() {int i = 0; for( ; ;) { statements; if(breaking condition) break; i++; }
  • 13. Program 17-18 Reverse Number #include<stdio.h> void main() {n, r, rn=0; scanf(“%d”, &n); while (n!=0) { r=n%10; n=n/10 ; rn=rn*10+r; } printf(“Reverese Number =%d”, rn); } Palindrome Number #include<stdio.h> void main() {n, r, T, rn=0; scanf(“%d”, &n); T=n; while (T!=0) { r=T%10; T=T/10 ; rn=rn*10+r; } if (rn==n) printf(“Palindrome Number); else printf(“Non-Palindrome Number); }
  • 14. Program 19 Prime Number #include<stdio.h> void main() {n, i; scanf(“%d”, &n); while (n % i != 0) i++; if (n==i) printf(“%d is prime”, n); }
  • 15. If you have any queries you can contact me at : [email protected]