SlideShare a Scribd company logo
1 of 23
Loops in C
Definition
 In any programming language, loops
are used to execute a set of
statements repeatedly until a
particular condition is satisfied.
 The loops in C language are used to
execute a block of code or a part of
the program several times.
 In other words, it iterates a code or
group of code many times.
Why use loops in C language?
 Suppose that you have to print table of
2, then you need to write 10 lines of
code.
 By using the loop statement, you can
do it by 2 or 3 lines of code only.
Advantage of loops in C
 1) It saves code.
 2) It helps to traverse the elements of
array.
How it works?
A sequence of statements are executed until a specified
condition is true. This sequence of statements to be executed is
kept inside the curly braces { } known as the Loop body. After
every execution of loop body, condition is verified, and if it is
found to be true the loop body is executed again. When the
condition check returns false, the loop body is not executed.
Types of Loops in C
There are 3 types of loops in C
language:
 while loop
 for loop
 do-while loop
While Loop
while loop can be addressed as
an entry control loop. It is completed
in 3 steps:
 Variable initialization.( e.g int x=0; )
 condition( e.g while( x<=10) )
 Variable increment or decrement ( x++
or x-- or x=x+2 )
 Syntax:
Flowchart:
Example
 Program to print first 10 natural
numbers
Program to print table for the
given number using while loop
#include <stdio.h>
#include <conio.h>
void main(){
int i=1,number=0;
clrscr();
printf("Enter a number: ");
scanf("%d",&number);
while(i<=10)
{
printf("%d n",(number*i));
i++;
}
getch();
}
Infinitive while loop in C
 If you pass 1 as a expression in while
loop, it will run infinite number of
times.
For Loop
 for loop is used to execute a set of
statements repeatedly until a
particular condition is satisfied. we can
say it an open ended loop.
 Syntax:
 In for loop we have exactly two semicolons,
one after initialization and second after
condition. In this loop we can have more than
one initialization or increment/decrement,
separated using comma operator. for loop
can have only one condition.
 The for loop is executed as follows:
◦ It first evaluates the initialization code.
◦ Then it checks the condition expression.
◦ If it is true, it executes the for-loop body.
◦ Then it evaluate the increment/decrement
condition and again follows from step 2.
◦ When the condition expression becomes false, it
exits the loop.
Flowchart:
Example:
 Program to print first n natural
numbers
Print table for the given number
using for loop
#include <stdio.h>
#include <conio.h>
void main(){
int i=1,number=0;
clrscr();
printf("Enter a number: ");
scanf("%d",&number);
for(i=1;i<=10;i++)
{
printf("%d n",(number*i));
}
getch();
}
Nested For loop
 We can also have nested for loops, i.e
one for loop inside another for loop.
 Syntax:
Example:
 Program to print half pyramid of
numbers
Infinitive for loop in C
 If you don't initialize any variable, check
condition and increment or decrement
variable in for loop, it is known as infinitive
for loop.
 In other words, if you place 2 semicolons in
for loop, it is known as infinitive for loop.
 If you run this program, you will see above
statement infinite times.
Do While Loop
 In some situations it is necessary to execute
body of the loop before testing the condition.
Such situations can be handled with the help
of do-while loop. do statement evaluates the
body of the loop first and at the end, the
condition is checked using while statement. It
means that for at least one time ,the body of
the loop will be executed, even though the
starting condition inside while is initialized to
false.
 Syntax:
Flowchart:
Example:
 Program to print first ten multiples of
5.
Program to print table for the
given number using do while
loop
#include <stdio.h>
#include <conio.h>
void main(){
int i=1,number=0;
clrscr();
printf("Enter a number: ");
scanf("%d",&number);
do{
printf("%d n",(number*i));
i++;
}while(i<=10);
getch();
}
Infinitive do while loop
If you pass 1 as a expression in do
while loop, it will run infinite number of
times.

More Related Content

What's hot (20)

Loops in c
Loops in cLoops in c
Loops in c
 
While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
 
Forloop
ForloopForloop
Forloop
 
Typecasting in c
Typecasting in cTypecasting in c
Typecasting in c
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
The Loops
The LoopsThe Loops
The Loops
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Loops in c++ programming language
Loops in c++ programming language Loops in c++ programming language
Loops in c++ programming language
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Looping (Computer programming and utilization)
Looping (Computer programming and utilization)Looping (Computer programming and utilization)
Looping (Computer programming and utilization)
 
inline function
inline function inline function
inline function
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
 
Loop(for, while, do while) condition Presentation
Loop(for, while, do while) condition PresentationLoop(for, while, do while) condition Presentation
Loop(for, while, do while) condition Presentation
 
Loops in C Programming
Loops in C ProgrammingLoops in C Programming
Loops in C Programming
 
Semaphores
SemaphoresSemaphores
Semaphores
 

Similar to Loops in c language

Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopPriyom Majumder
 
C++ control structure
C++ control structureC++ control structure
C++ control structurebluejayjunior
 
Programming Fundamentals lecture 8
Programming Fundamentals lecture 8Programming Fundamentals lecture 8
Programming Fundamentals lecture 8REHAN IJAZ
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02CIMAP
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitionsaltwirqi
 
loops and iteration.docx
loops and iteration.docxloops and iteration.docx
loops and iteration.docxJavvajiVenkat
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxLikhil181
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c languagetanmaymodi4
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguageTanmay Modi
 

Similar to Loops in c language (20)

Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
C operators
C operatorsC operators
C operators
 
C++ control structure
C++ control structureC++ control structure
C++ control structure
 
Programming Fundamentals lecture 8
Programming Fundamentals lecture 8Programming Fundamentals lecture 8
Programming Fundamentals lecture 8
 
while loop in C.pptx
while loop in C.pptxwhile loop in C.pptx
while loop in C.pptx
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Looping statements
Looping statementsLooping statements
Looping statements
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitions
 
loops and iteration.docx
loops and iteration.docxloops and iteration.docx
loops and iteration.docx
 
Matlab Script - Loop Control
Matlab Script - Loop ControlMatlab Script - Loop Control
Matlab Script - Loop Control
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptx
 
[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 
Loops in c
Loops in cLoops in c
Loops in c
 

More from Tanmay Modi

Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguageTanmay Modi
 
Pointers in c language
Pointers in c languagePointers in c language
Pointers in c languageTanmay Modi
 
Generations of computers
Generations of computersGenerations of computers
Generations of computersTanmay Modi
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c languageTanmay Modi
 
Union in c language
Union in c languageUnion in c language
Union in c languageTanmay Modi
 
Structures in c language
Structures in c languageStructures in c language
Structures in c languageTanmay Modi
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c languageTanmay Modi
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c languageTanmay Modi
 
Dynamic memory allocation in c language
Dynamic memory allocation in c languageDynamic memory allocation in c language
Dynamic memory allocation in c languageTanmay Modi
 
Arrays in c v1 09102017
Arrays in c v1 09102017Arrays in c v1 09102017
Arrays in c v1 09102017Tanmay Modi
 

More from Tanmay Modi (11)

Preprocessor directives in c laguage
Preprocessor directives in c laguagePreprocessor directives in c laguage
Preprocessor directives in c laguage
 
Pointers in c language
Pointers in c languagePointers in c language
Pointers in c language
 
Generations of computers
Generations of computersGenerations of computers
Generations of computers
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Union in c language
Union in c languageUnion in c language
Union in c language
 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
 
Operators inc c language
Operators inc c languageOperators inc c language
Operators inc c language
 
Functions in c language
Functions in c languageFunctions in c language
Functions in c language
 
Dynamic memory allocation in c language
Dynamic memory allocation in c languageDynamic memory allocation in c language
Dynamic memory allocation in c language
 
Arrays in c v1 09102017
Arrays in c v1 09102017Arrays in c v1 09102017
Arrays in c v1 09102017
 
Cryptocurrency
Cryptocurrency Cryptocurrency
Cryptocurrency
 

Recently uploaded

DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 

Recently uploaded (20)

DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 

Loops in c language

  • 2. Definition  In any programming language, loops are used to execute a set of statements repeatedly until a particular condition is satisfied.  The loops in C language are used to execute a block of code or a part of the program several times.  In other words, it iterates a code or group of code many times.
  • 3. Why use loops in C language?  Suppose that you have to print table of 2, then you need to write 10 lines of code.  By using the loop statement, you can do it by 2 or 3 lines of code only. Advantage of loops in C  1) It saves code.  2) It helps to traverse the elements of array.
  • 4. How it works? A sequence of statements are executed until a specified condition is true. This sequence of statements to be executed is kept inside the curly braces { } known as the Loop body. After every execution of loop body, condition is verified, and if it is found to be true the loop body is executed again. When the condition check returns false, the loop body is not executed.
  • 5. Types of Loops in C There are 3 types of loops in C language:  while loop  for loop  do-while loop
  • 6. While Loop while loop can be addressed as an entry control loop. It is completed in 3 steps:  Variable initialization.( e.g int x=0; )  condition( e.g while( x<=10) )  Variable increment or decrement ( x++ or x-- or x=x+2 )  Syntax:
  • 8. Example  Program to print first 10 natural numbers
  • 9. Program to print table for the given number using while loop #include <stdio.h> #include <conio.h> void main(){ int i=1,number=0; clrscr(); printf("Enter a number: "); scanf("%d",&number); while(i<=10) { printf("%d n",(number*i)); i++; } getch(); }
  • 10. Infinitive while loop in C  If you pass 1 as a expression in while loop, it will run infinite number of times.
  • 11. For Loop  for loop is used to execute a set of statements repeatedly until a particular condition is satisfied. we can say it an open ended loop.  Syntax:
  • 12.  In for loop we have exactly two semicolons, one after initialization and second after condition. In this loop we can have more than one initialization or increment/decrement, separated using comma operator. for loop can have only one condition.  The for loop is executed as follows: ◦ It first evaluates the initialization code. ◦ Then it checks the condition expression. ◦ If it is true, it executes the for-loop body. ◦ Then it evaluate the increment/decrement condition and again follows from step 2. ◦ When the condition expression becomes false, it exits the loop.
  • 14. Example:  Program to print first n natural numbers
  • 15. Print table for the given number using for loop #include <stdio.h> #include <conio.h> void main(){ int i=1,number=0; clrscr(); printf("Enter a number: "); scanf("%d",&number); for(i=1;i<=10;i++) { printf("%d n",(number*i)); } getch(); }
  • 16. Nested For loop  We can also have nested for loops, i.e one for loop inside another for loop.  Syntax:
  • 17. Example:  Program to print half pyramid of numbers
  • 18. Infinitive for loop in C  If you don't initialize any variable, check condition and increment or decrement variable in for loop, it is known as infinitive for loop.  In other words, if you place 2 semicolons in for loop, it is known as infinitive for loop.  If you run this program, you will see above statement infinite times.
  • 19. Do While Loop  In some situations it is necessary to execute body of the loop before testing the condition. Such situations can be handled with the help of do-while loop. do statement evaluates the body of the loop first and at the end, the condition is checked using while statement. It means that for at least one time ,the body of the loop will be executed, even though the starting condition inside while is initialized to false.  Syntax:
  • 21. Example:  Program to print first ten multiples of 5.
  • 22. Program to print table for the given number using do while loop #include <stdio.h> #include <conio.h> void main(){ int i=1,number=0; clrscr(); printf("Enter a number: "); scanf("%d",&number); do{ printf("%d n",(number*i)); i++; }while(i<=10); getch(); }
  • 23. Infinitive do while loop If you pass 1 as a expression in do while loop, it will run infinite number of times.