SlideShare a Scribd company logo
Looping
statements in CPresented by,
S.Jeyalakshmi B.E.,
Sr.Lecturer/CE
MSPVL Polytechnic college, Pavoorchatram
Repetition
You Will Want to display HAI
More Than Once
HAI
HAI
HAI
HAI
HAI
HAI
HAI
HAI
You Could Code The ā€˜HAIā€™
Like This
printf("HAI");
printf(" HAI ");
printf(" HAI ");
printf(" HAI ");
printf(" HAI ");
printf(" HAI ");
printf(" HAI ");
printf(" HAI ");
No good programmer
does this!
Loop
ā€¢ Donā€™t need to write this code 8 times.
ā€¢ A loop is a piece of code which allows you to repeat
some code more than once without having to write it out
more than once.
printf("HAI ");
Looping statements
ā€¢ Loops provide a way to repeat commands and control
how many times they are repeated.
ā€¢ 3 types.
ā€¢ while
ā€¢ do-while
ā€¢ for
while ( expression )
{
Single statement
or
Block of statements;
}
While
Syntax
7
Flow chart
If the test condition is true: the
statements get executed until the
condition becomes false.
While - Example
#include <stdio.h>
main()
{
int i = 0;
while ( i < 10 )
{
printf("Hello %dn", i );
i ++;
}
}
OUTPUT
Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
Hello 7
Hello 8
Hello 9
do
{
Single statement
or
Block of statements;
}while ( expression )
Do While
Syntax
9
Flow chart
The statements get executed once.
Then the condition is evaluated. If the
test condition is true: until the
condition becomes false.
Do While - Example
#include <stdio.h>
main()
{
int i = 0;
do
{
printf("Hello %dn", i );
i ++;
} while ( i < 10 )
}
OUTPUT
Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
Hello 7
Hello 8
Hello 9
for (initialization_expression;loop_condition;increment_expression)
{
// statements
}
)
for
Syntax
11
Flow chart
for- Example
#include <stdio.h>
main()
{
int i;
for( i = 0; i <10; i ++ )
{
printf("Hello %dn", i );
}
}
OUTPUT
Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
Hello 7
Hello 8
Hello 9
Break
ā€¢ It is used in terminating the loop immediately after it is
encountered.
ā€¢ It can be used inside a switch, for loop, while loop and
do-while loop.
Break- Example
#include <stdio.h>
main()
{
int i;
for( i = 0; i <10; i ++ )
{
printf("Hello %dn", i );
if(i==4)
break;
}
}
OUTPUT
Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
Continue
ā€¢ It is sometimes desirable to skip some statements inside
the loop.
ā€¢ In such cases, continue statements are used.
Continue - Example
#include <stdio.h>
main()
{
int i;
for( i = 0; i <10; i ++ )
{
printf("Hello %dt", i );
if(i==4)
continue;
printf(ā€œWelcomenā€);
}
}
OUTPUT
Hello 0 Welcome
Hello 1 Welcome
Hello 2 Welcome
Hello 3 Welcome
Hello 4
Hello 5 Welcome
Hello 6 Welcome
Hello 7 Welcome
Hello 8 Welcome
Hello 9 Welcome

More Related Content

What's hot

Loops c++
Loops c++Loops c++
Loops c++
Shivani Singh
Ā 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Shuvongkor Barman
Ā 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Harendra Singh
Ā 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
Ā 
Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
Ā 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
Ā 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
Ā 
String functions in C
String functions in CString functions in C
Forloop
ForloopForloop
Forloop
Dipen Vasoya
Ā 
Different loops in C
Different loops in CDifferent loops in C
Different loops in C
Md. Arif Hossain
Ā 
C if else
C if elseC if else
C if else
Ritwik Das
Ā 
Data types in C
Data types in CData types in C
Data types in C
Tarun Sharma
Ā 
Loops in c++ programming language
Loops in c++ programming language Loops in c++ programming language
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid
Ā 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
Ā 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C programDavid Livingston J
Ā 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
programming9
Ā 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
Ā 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
tanmaymodi4
Ā 

What's hot (20)

Loops c++
Loops c++Loops c++
Loops c++
Ā 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
Ā 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
Ā 
10. switch case
10. switch case10. switch case
10. switch case
Ā 
Control statements in c
Control statements in cControl statements in c
Control statements in c
Ā 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Ā 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Ā 
String functions in C
String functions in CString functions in C
String functions in C
Ā 
Forloop
ForloopForloop
Forloop
Ā 
Different loops in C
Different loops in CDifferent loops in C
Different loops in C
Ā 
C if else
C if elseC if else
C if else
Ā 
Loops in c
Loops in cLoops in c
Loops in c
Ā 
Data types in C
Data types in CData types in C
Data types in C
Ā 
Loops in c++ programming language
Loops in c++ programming language Loops in c++ programming language
Loops in c++ programming language
Ā 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Ā 
Functions in C
Functions in CFunctions in C
Functions in C
Ā 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
Ā 
Operators in C Programming
Operators in C ProgrammingOperators in C Programming
Operators in C Programming
Ā 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
Ā 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
Ā 

Viewers also liked

INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
Abhishek Dwivedi
Ā 
Looping and Switchcase BDCR
Looping and Switchcase BDCRLooping and Switchcase BDCR
Looping and Switchcase BDCRberiver
Ā 
Fundamentals of programming finals.ajang
Fundamentals of programming finals.ajangFundamentals of programming finals.ajang
Fundamentals of programming finals.ajangJaricka Angelyd Marquez
Ā 
Looping in C
Looping in CLooping in C
Looping in C
Prabhu Govind
Ā 
Looping statement
Looping statementLooping statement
Looping statementilakkiya
Ā 
Looping and switch cases
Looping and switch casesLooping and switch cases
Looping and switch casesMeoRamos
Ā 
Loops
LoopsLoops
Loops
abdulmanan366
Ā 
Conditional statement
Conditional statementConditional statement
Conditional statement
Maxie Santos
Ā 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
Himanshu Negi
Ā 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
Gagan Deep
Ā 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
Ideal Eyes Business College
Ā 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
Haard Shah
Ā 

Viewers also liked (14)

INTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMINGINTRODUCTION TO C PROGRAMMING
INTRODUCTION TO C PROGRAMMING
Ā 
Looping and Switchcase BDCR
Looping and Switchcase BDCRLooping and Switchcase BDCR
Looping and Switchcase BDCR
Ā 
Fundamentals of programming finals.ajang
Fundamentals of programming finals.ajangFundamentals of programming finals.ajang
Fundamentals of programming finals.ajang
Ā 
Looping in C
Looping in CLooping in C
Looping in C
Ā 
Lecture05(control structure part ii)
Lecture05(control structure part ii)Lecture05(control structure part ii)
Lecture05(control structure part ii)
Ā 
Looping
LoopingLooping
Looping
Ā 
Looping statement
Looping statementLooping statement
Looping statement
Ā 
Looping and switch cases
Looping and switch casesLooping and switch cases
Looping and switch cases
Ā 
Loops
LoopsLoops
Loops
Ā 
Conditional statement
Conditional statementConditional statement
Conditional statement
Ā 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
Ā 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
Ā 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
Ā 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
Ā 

Similar to Looping statements in C

C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
Gagan Deep
Ā 
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in CSPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
Mohammad Imam Hossain
Ā 
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
DrDineshenScientist
Ā 
Programming basics
Programming basicsProgramming basics
Programming basics
246paa
Ā 
C++ programming
C++ programmingC++ programming
C++ programmingviancagerone
Ā 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and loopingaprilyyy
Ā 
CPAP.com Introduction To Coding: Part 2
CPAP.com Introduction To Coding: Part 2CPAP.com Introduction To Coding: Part 2
CPAP.com Introduction To Coding: Part 2johnnygoodman
Ā 
C Language Lecture 7
C Language Lecture 7C Language Lecture 7
C Language Lecture 7
Shahzaib Ajmal
Ā 
What Is Php
What Is PhpWhat Is Php
What Is Php
AVC
Ā 
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
santosh147365
Ā 
C++ programming
C++ programmingC++ programming
C++ programmingviancagerone
Ā 
loops and iteration.docx
loops and iteration.docxloops and iteration.docx
loops and iteration.docx
JavvajiVenkat
Ā 
Loops in c
Loops in cLoops in c
Loops in c
shubhampandav3
Ā 
Bsit1
Bsit1Bsit1
Bsit1jigeno
Ā 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping new
aprilyyy
Ā 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kimkimberly_Bm10203
Ā 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jamJamaicaAubreyUnite
Ā 
Fundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinaFundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinarurumedina
Ā 

Similar to Looping statements in C (20)

C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
Ā 
SPL 8 | Loop Statements in C
SPL 8 | Loop Statements in CSPL 8 | Loop Statements in C
SPL 8 | Loop Statements in C
Ā 
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
Ā 
Programming basics
Programming basicsProgramming basics
Programming basics
Ā 
if,loop,switch
if,loop,switchif,loop,switch
if,loop,switch
Ā 
C++ programming
C++ programmingC++ programming
C++ programming
Ā 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
Ā 
CPAP.com Introduction To Coding: Part 2
CPAP.com Introduction To Coding: Part 2CPAP.com Introduction To Coding: Part 2
CPAP.com Introduction To Coding: Part 2
Ā 
C Language Lecture 7
C Language Lecture 7C Language Lecture 7
C Language Lecture 7
Ā 
What Is Php
What Is PhpWhat Is Php
What Is Php
Ā 
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
Ā 
C++ programming
C++ programmingC++ programming
C++ programming
Ā 
loops and iteration.docx
loops and iteration.docxloops and iteration.docx
loops and iteration.docx
Ā 
Loops in c
Loops in cLoops in c
Loops in c
Ā 
Bsit1
Bsit1Bsit1
Bsit1
Ā 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping new
Ā 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kim
Ā 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
Ā 
PHP
PHPPHP
PHP
Ā 
Fundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinaFundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medina
Ā 

Recently uploaded

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
Ā 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
Ā 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
Ā 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
Ā 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
Ā 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
Ā 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
Ā 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
Ā 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
Ā 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
Ā 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
Ā 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
Ā 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
Ā 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
Ā 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
Ā 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
Ā 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
Ā 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
Ā 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
Ā 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
Ā 

Recently uploaded (20)

De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Ā 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Ā 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
Ā 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Ā 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Ā 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
Ā 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
Ā 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Ā 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
Ā 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ā 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Ā 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Ā 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Ā 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Ā 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
Ā 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Ā 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Ā 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
Ā 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Ā 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Ā 

Looping statements in C

  • 1. Looping statements in CPresented by, S.Jeyalakshmi B.E., Sr.Lecturer/CE MSPVL Polytechnic college, Pavoorchatram
  • 3. You Will Want to display HAI More Than Once HAI HAI HAI HAI HAI HAI HAI HAI
  • 4. You Could Code The ā€˜HAIā€™ Like This printf("HAI"); printf(" HAI "); printf(" HAI "); printf(" HAI "); printf(" HAI "); printf(" HAI "); printf(" HAI "); printf(" HAI "); No good programmer does this!
  • 5. Loop ā€¢ Donā€™t need to write this code 8 times. ā€¢ A loop is a piece of code which allows you to repeat some code more than once without having to write it out more than once. printf("HAI ");
  • 6. Looping statements ā€¢ Loops provide a way to repeat commands and control how many times they are repeated. ā€¢ 3 types. ā€¢ while ā€¢ do-while ā€¢ for
  • 7. while ( expression ) { Single statement or Block of statements; } While Syntax 7 Flow chart If the test condition is true: the statements get executed until the condition becomes false.
  • 8. While - Example #include <stdio.h> main() { int i = 0; while ( i < 10 ) { printf("Hello %dn", i ); i ++; } } OUTPUT Hello 0 Hello 1 Hello 2 Hello 3 Hello 4 Hello 5 Hello 6 Hello 7 Hello 8 Hello 9
  • 9. do { Single statement or Block of statements; }while ( expression ) Do While Syntax 9 Flow chart The statements get executed once. Then the condition is evaluated. If the test condition is true: until the condition becomes false.
  • 10. Do While - Example #include <stdio.h> main() { int i = 0; do { printf("Hello %dn", i ); i ++; } while ( i < 10 ) } OUTPUT Hello 0 Hello 1 Hello 2 Hello 3 Hello 4 Hello 5 Hello 6 Hello 7 Hello 8 Hello 9
  • 12. for- Example #include <stdio.h> main() { int i; for( i = 0; i <10; i ++ ) { printf("Hello %dn", i ); } } OUTPUT Hello 0 Hello 1 Hello 2 Hello 3 Hello 4 Hello 5 Hello 6 Hello 7 Hello 8 Hello 9
  • 13. Break ā€¢ It is used in terminating the loop immediately after it is encountered. ā€¢ It can be used inside a switch, for loop, while loop and do-while loop.
  • 14. Break- Example #include <stdio.h> main() { int i; for( i = 0; i <10; i ++ ) { printf("Hello %dn", i ); if(i==4) break; } } OUTPUT Hello 0 Hello 1 Hello 2 Hello 3 Hello 4
  • 15. Continue ā€¢ It is sometimes desirable to skip some statements inside the loop. ā€¢ In such cases, continue statements are used.
  • 16. Continue - Example #include <stdio.h> main() { int i; for( i = 0; i <10; i ++ ) { printf("Hello %dt", i ); if(i==4) continue; printf(ā€œWelcomenā€); } } OUTPUT Hello 0 Welcome Hello 1 Welcome Hello 2 Welcome Hello 3 Welcome Hello 4 Hello 5 Welcome Hello 6 Welcome Hello 7 Welcome Hello 8 Welcome Hello 9 Welcome