SlideShare a Scribd company logo
9
Most read
11
Most read
12
Most read
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

PPT
Biometric's final ppt
PPTX
The Loops
PPTX
While , For , Do-While Loop
PPTX
Union in C programming
PPT
While loop
PPTX
Reproduction in animals by gaurav ghankhede
PPTX
Loops in C Programming Language
Biometric's final ppt
The Loops
While , For , Do-While Loop
Union in C programming
While loop
Reproduction in animals by gaurav ghankhede
Loops in C Programming Language

What's hot (20)

PDF
Operators in python
PPTX
Loops c++
PPTX
Function in C program
PPTX
Pointers in C Programming
PPT
Operators in C++
PPT
RECURSION IN C
PPTX
Functions in c
PPTX
CONDITIONAL STATEMENT IN C LANGUAGE
PPTX
Loops in c programming
PPTX
Strings in C language
PPT
Operators in C Programming
PPSX
Break and continue
PPT
Input and output in C++
PPTX
Looping statement in python
PPTX
Operators and expressions in C++
PPTX
Operators in java
PPTX
Control Flow Statements
PPTX
C++ Overview PPT
PPTX
Inheritance in java
PPTX
Operators in python
Loops c++
Function in C program
Pointers in C Programming
Operators in C++
RECURSION IN C
Functions in c
CONDITIONAL STATEMENT IN C LANGUAGE
Loops in c programming
Strings in C language
Operators in C Programming
Break and continue
Input and output in C++
Looping statement in python
Operators and expressions in C++
Operators in java
Control Flow Statements
C++ Overview PPT
Inheritance in java
Ad

Viewers also liked (14)

PPSX
INTRODUCTION TO C PROGRAMMING
PPTX
Looping and Switchcase BDCR
PPT
Fundamentals of programming finals.ajang
PPT
Looping in C
PDF
Lecture05(control structure part ii)
PPTX
Looping statement
PPTX
Looping and switch cases
PPT
PPSX
Conditional statement
PPTX
Loops in C Programming
PPSX
C Programming : Arrays
PPTX
C decision making and looping.
INTRODUCTION TO C PROGRAMMING
Looping and Switchcase BDCR
Fundamentals of programming finals.ajang
Looping in C
Lecture05(control structure part ii)
Looping statement
Looping and switch cases
Conditional statement
Loops in C Programming
C Programming : Arrays
C decision making and looping.
Ad

Similar to Looping statements in C (20)

PPSX
C lecture 3 control statements slideshare
PDF
SPL 8 | Loop Statements in C
PDF
Workbook_2_Problem_Solving_and_programming.pdf
PDF
Programming basics
PPT
C++ programming
PPTX
Switch case and looping
PPT
CPAP.com Introduction To Coding: Part 2
PDF
C Language Lecture 7
PPT
What Is Php
 
PDF
3. Flow Controls in C (Part II).pdf
PPT
C++ programming
DOCX
loops and iteration.docx
PPTX
Loops in c
PPSX
Bsit1
PPTX
Switch case and looping new
PPTX
Switch case and looping kim
PPTX
Switch case and looping jam
PPTX
PPTX
Fundamentals of prog. by rubferd medina
C lecture 3 control statements slideshare
SPL 8 | Loop Statements in C
Workbook_2_Problem_Solving_and_programming.pdf
Programming basics
C++ programming
Switch case and looping
CPAP.com Introduction To Coding: Part 2
C Language Lecture 7
What Is Php
 
3. Flow Controls in C (Part II).pdf
C++ programming
loops and iteration.docx
Loops in c
Bsit1
Switch case and looping new
Switch case and looping kim
Switch case and looping jam
Fundamentals of prog. by rubferd medina

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
KodekX | Application Modernization Development
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Cloud computing and distributed systems.
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Review of recent advances in non-invasive hemoglobin estimation
NewMind AI Weekly Chronicles - August'25 Week I
Understanding_Digital_Forensics_Presentation.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Empathic Computing: Creating Shared Understanding
Machine learning based COVID-19 study performance prediction
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Network Security Unit 5.pdf for BCA BBA.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Dropbox Q2 2025 Financial Results & Investor Presentation
KodekX | Application Modernization Development
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Cloud computing and distributed systems.
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Electronic commerce courselecture one. Pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Programs and apps: productivity, graphics, security and other tools
Review of recent advances in non-invasive hemoglobin estimation

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