SlideShare a Scribd company logo
1 of 10
Loop execute a set of instructions
repeatedly for a certain number of
times
FOR LOOP

WHILE LOOP
DO-WHILE LOOP
• Execute a sequence of statements multiple
times and abbreviates the code that manages
the loop variable.
SYNTAX:
for(INITIALIZATION;CONDITION;INCREMENT/DECREMENT)
{
// Code for the for loop's body
}
EXAMPLE
#include <stdio.h>
#include<conio.h>
void main()
{
int i;
for( i = 0; i <=10 ; i ++ )
{
printf("Hello %dn", i );
}
getch();
}

0UTPUT
Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
Hello 7
Hello 8
Hello 9
Hello 10
• Entry-check loop
• It tests the condition before executing the
loop body.
• Repeats a statement or group of statements
while a given condition is true
Syntax:
while ( condition )
{
/* code */
}
EXAMPLE
#include<stdio.h>
#include<conio.h>
Void main()
{
int i = 10;
while ( i > 0 )
{
printf("Hello %dn", i );
i = i -1;
}
getch();
}

OUTPUT
Hello 10
Hello 9
Hello 8
Hello 7
Hello 6
Hello 5
Hello 4
Hello 3
Hello 2
Hello 1
• Exit –check loop
• Like a while statement, except that it tests the
condition at the end of the loop body
• It will be executed at least once in the execution
of the program
SYNTAX:
do
{
/* code */
}
while ( condition );
EXAMPLE
#include <stdio.h>
#include<conio.h>
Void main()
{
int i = 10;
do
{
printf("Hello %dn", i );
i = i -1;
}
while ( i > 0 );
getch();
}

OUTPUT
Hello 10
Hello 9
Hello 8
Hello 7
Hello 6
Hello 5
Hello 4
Hello 3
Hello 2
Hello 1
Loops

More Related Content

What's hot

Easily mockingdependenciesinc++ 2
Easily mockingdependenciesinc++ 2Easily mockingdependenciesinc++ 2
Easily mockingdependenciesinc++ 2drewz lin
 
Os Practical Assignment 1
Os Practical Assignment 1Os Practical Assignment 1
Os Practical Assignment 1Emmanuel Garcia
 
One definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим житьOne definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим житьPlatonov Sergey
 
Repetition loop
Repetition loopRepetition loop
Repetition loopAdnan Rana
 
Javascript basics
Javascript basicsJavascript basics
Javascript basicsFin Chen
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsNodeXperts
 
Theorical 1
Theorical 1Theorical 1
Theorical 1everblut
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges✅ William Pinaud
 
関西 Unconferance Sphinx かわいいよ Sphinx
関西 Unconferance Sphinx かわいいよ Sphinx関西 Unconferance Sphinx かわいいよ Sphinx
関西 Unconferance Sphinx かわいいよ SphinxShinya Ohyanagi
 
File Transfer Through Sockets
File Transfer Through SocketsFile Transfer Through Sockets
File Transfer Through Socketsadil raja
 
Fine grain process control 2nd nov
Fine grain process control 2nd novFine grain process control 2nd nov
Fine grain process control 2nd novSurendraGangarapu1
 
Teorical 1
Teorical 1Teorical 1
Teorical 1everblut
 
using Virtualbox NAT and shared folder
using Virtualbox NAT and shared folderusing Virtualbox NAT and shared folder
using Virtualbox NAT and shared folderYingshiuan Pan
 

What's hot (20)

Easily mockingdependenciesinc++ 2
Easily mockingdependenciesinc++ 2Easily mockingdependenciesinc++ 2
Easily mockingdependenciesinc++ 2
 
Os Practical Assignment 1
Os Practical Assignment 1Os Practical Assignment 1
Os Practical Assignment 1
 
One definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим житьOne definition rule - что это такое, и как с этим жить
One definition rule - что это такое, и как с этим жить
 
Repetition loop
Repetition loopRepetition loop
Repetition loop
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Theorical 1
Theorical 1Theorical 1
Theorical 1
 
Unit test
Unit testUnit test
Unit test
 
Java loops
Java loopsJava loops
Java loops
 
Usp
UspUsp
Usp
 
Javascript: The Important Bits
Javascript: The Important BitsJavascript: The Important Bits
Javascript: The Important Bits
 
PHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP LimogesPHP in 2018 - Q4 - AFUP Limoges
PHP in 2018 - Q4 - AFUP Limoges
 
関西 Unconferance Sphinx かわいいよ Sphinx
関西 Unconferance Sphinx かわいいよ Sphinx関西 Unconferance Sphinx かわいいよ Sphinx
関西 Unconferance Sphinx かわいいよ Sphinx
 
Java Programming: Loops
Java Programming: LoopsJava Programming: Loops
Java Programming: Loops
 
Primi passi con Project Tango
Primi passi con Project TangoPrimi passi con Project Tango
Primi passi con Project Tango
 
Loops in JavaScript
Loops in JavaScriptLoops in JavaScript
Loops in JavaScript
 
File Transfer Through Sockets
File Transfer Through SocketsFile Transfer Through Sockets
File Transfer Through Sockets
 
Fine grain process control 2nd nov
Fine grain process control 2nd novFine grain process control 2nd nov
Fine grain process control 2nd nov
 
Teorical 1
Teorical 1Teorical 1
Teorical 1
 
using Virtualbox NAT and shared folder
using Virtualbox NAT and shared folderusing Virtualbox NAT and shared folder
using Virtualbox NAT and shared folder
 

Similar to Loops

5.pptx fundamental programing one branch
5.pptx fundamental programing one branch5.pptx fundamental programing one branch
5.pptx fundamental programing one branchssuserdde43b
 
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRLoops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRKrishna Raj
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2rohassanie
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)jewelyngrace
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in CJeya Lakshmi
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Mohd Harris Ahmad Jaal
 
Chp4_C++_Control Structures-Part2_Iteration.pptx
Chp4_C++_Control Structures-Part2_Iteration.pptxChp4_C++_Control Structures-Part2_Iteration.pptx
Chp4_C++_Control Structures-Part2_Iteration.pptxssuser10ed71
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and loopingaprilyyy
 
Unit Testing: Special Cases
Unit Testing: Special CasesUnit Testing: Special Cases
Unit Testing: Special CasesCiklum Ukraine
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition StructurePRN USM
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programmingCHANDAN KUMAR
 

Similar to Loops (20)

5.pptx fundamental programing one branch
5.pptx fundamental programing one branch5.pptx fundamental programing one branch
5.pptx fundamental programing one branch
 
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRLoops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
 
Loops c++
Loops c++Loops c++
Loops c++
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 
Loop structures
Loop structuresLoop structures
Loop structures
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
While and For Loops
While and For LoopsWhile and For Loops
While and For Loops
 
Loops In C++
Loops In C++Loops In C++
Loops In C++
 
Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2Web Application Development using PHP Chapter 2
Web Application Development using PHP Chapter 2
 
Loops in c++
Loops in c++Loops in c++
Loops in c++
 
06 Loops
06 Loops06 Loops
06 Loops
 
Chp4_C++_Control Structures-Part2_Iteration.pptx
Chp4_C++_Control Structures-Part2_Iteration.pptxChp4_C++_Control Structures-Part2_Iteration.pptx
Chp4_C++_Control Structures-Part2_Iteration.pptx
 
Oop object oriented programing topics
Oop object oriented programing topicsOop object oriented programing topics
Oop object oriented programing topics
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Unit Testing: Special Cases
Unit Testing: Special CasesUnit Testing: Special Cases
Unit Testing: Special Cases
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
 
Statements and Conditions in PHP
Statements and Conditions in PHPStatements and Conditions in PHP
Statements and Conditions in PHP
 
Loops (Refined).pptx
Loops (Refined).pptxLoops (Refined).pptx
Loops (Refined).pptx
 
Loops in c programming
Loops in c programmingLoops in c programming
Loops in c programming
 

Loops