SlideShare a Scribd company logo
1 of 15
LOOP IN C++:
The mechanism through which a statement or set of statement
can be executed repeatedly is called loop .
The statements that are executed repeatedly are called body of
loop.
The body of loop can be executed repeatedly for a specified
number of times or until the given condition remains true .
In c++ there are four types of loop as;
1) For loop
2) while loop
3) Do while loop
4) Nested loop
@Muhammad
–For loop
• The “for” loop is used to execute a
statement or set of statements repeatedly
for a specific numbers of times
• This loop is also known as counter loop.
Syntax of for loop
For{initialization;condition;increment/decrement}
{
}
Statements;
Next statement;
@Muhamm
The “for”loop is executed as follows;
Working of
For loop
When control enters into the loop
1)First initialization part is executed . It is executed only for the first time
2)After executing initialization part , the condition is evaluated.if it is
True,then body of loop is executed.
3)After executing body of loop, increament/decreament part is executed
increament/decreament part is last statement of body of “for” loop. .
@Muhammad
• Our Services
• Insert the title of your subtitle Here
Flow chart of for loop
intialization
Body of loop
Increament/decreament
Next statement
True
False
@Muhamm
Example
of for loop
#include <iostream.h>
#include<conio.h>
Main();
{
Int n;
For (n=1;n<=10;n++)
cout <<n<<endl;
Cout<<“ok”;
}
@Muhammad
While loop
• The “while loop ” is conditional loop structure it is used to
Execute a statement or set of statement as long as the given
condtioin remain true
• This loop structure is used when the programmer does not know in
advance
Syntax of while loop;
While (condition)
{
statement;
}
Next – statement;
@Muhammad
The “for”loop is executed as follows;
• When a “while ”loop statement is executed the condition
is evaluate first
• If the condition is true then body of loop is executed
• After executing the body of loop, the execution control goes back to t
he “while”statement and evaluates the condition again.
• If the given condition is still true , the body of loop is executed again.
This process is repeated.
• When the given condition become false at any stage during
• execution ,the loop is terminated.
@Muhamma
• Our Services
• Insert the title of your subtitle Here
Flow chart of ”while”loop
Body of loop
Next statement
False
True
@Muhamm
Example of “while ” loop
#include<iostream.h>
#include<conio.h>
Main()
{
Int num;
Num=1;
While(num<=15)
{
If (num%3==0)
Cout<<num<<endl;
Num=num+1;
}
}
@Muhammad
DO WHILE LOOP;
• as while loop ,do while loop is also used to execute a state
ment or set of statement as long as the given condition rem
ains true
• The condition comes after the body of loop
• The condition is evaluate after executing the body of loop
The body of loop must be executed at least once even if
The condition is false
• Semicolon(;) is given after the while (condition)
Syntax of Do while loop;
Initialize
Do {
Body of loop
Updation
}
While (condition) @Muhammad
Flow chart of ”Do while”loop
Body of loop
Next statement
False
True
@Muhammad
Example of “Do while ”
loop
#include<iostream.h>
#include<conio.h>
Main()
{
Int i=1;
Do
{
Cout<<i<<“/n”;
i++;
}
While (1<=10);
}
@Muhamma
Nested loop;
• A nested loop is a loop within a loop, an inner loop within
the body of an outer one.
• How this works is that the first pass of the outer loop triggers
the inner loop, which executes to completion. Then the
second pass of the outer loop triggers the inner loop again.
• This repeats until the outer loop finishes
Syntax of nested loop;
Outer loop
{
statement (s)-1
Inner-loop
{
Body of inner loop
}
Statement (s)-2
}
Next – statement;
@Muhammad
The “nested”loop is executed as follows;
• The condition given in outer is evaluated.if condition is true
Controls enters inside the body of outer loop.otherwise loop is
Terminated.
• If body of outer loop contains any statement before the inner
loop, it is executed .
@Muhammad
Example of “nested”
loop
#include<iostream.h>
#include<conio.h>
Main()
{
Int u,i;
U=1;
While (u<=3)
{
Cout <<u<<endl;
For (i=1;i<=2;i++)
Cout <<“I love Pakistann”;
U=u+1;
}
}
@Muhamma

More Related Content

What's hot (20)

Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Loops in c
Loops in cLoops in c
Loops in c
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Forloop
ForloopForloop
Forloop
 
Function in C program
Function in C programFunction in C program
Function in C program
 
Functions in C
Functions in CFunctions in C
Functions in C
 
The Loops
The LoopsThe Loops
The Loops
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
 
Presentation on Function in C Programming
Presentation on Function in C ProgrammingPresentation on Function in C Programming
Presentation on Function in C Programming
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
Control structure C++
Control structure C++Control structure C++
Control structure C++
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
C if else
C if elseC if else
C if else
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
C tokens
C tokensC tokens
C tokens
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 
structured programming
structured programmingstructured programming
structured programming
 
10. switch case
10. switch case10. switch case
10. switch case
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 

Similar to Loops in c++ programming language

Similar to Loops in c++ programming language (20)

Looping (Computer programming and utilization)
Looping (Computer programming and utilization)Looping (Computer programming and utilization)
Looping (Computer programming and utilization)
 
Java Repetiotion Statements
Java Repetiotion StatementsJava Repetiotion Statements
Java Repetiotion Statements
 
loops and iteration.docx
loops and iteration.docxloops and iteration.docx
loops and iteration.docx
 
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
 
Loops In C++
Loops In C++Loops In C++
Loops In C++
 
Loop (Computer programming and utilization)
Loop (Computer programming and utilization)Loop (Computer programming and utilization)
Loop (Computer programming and utilization)
 
cpu.pdf
cpu.pdfcpu.pdf
cpu.pdf
 
Loop structures
Loop structuresLoop structures
Loop structures
 
Loops in C.net.pptx
Loops in C.net.pptxLoops in C.net.pptx
Loops in C.net.pptx
 
Loop
LoopLoop
Loop
 
whileloop-161225171903.pdf
whileloop-161225171903.pdfwhileloop-161225171903.pdf
whileloop-161225171903.pdf
 
While loop
While loopWhile loop
While loop
 
Chapter 9 - Loops in C++
Chapter 9 - Loops in C++Chapter 9 - Loops in C++
Chapter 9 - Loops in C++
 
Looping statements
Looping statementsLooping statements
Looping statements
 
itretion.docx
itretion.docxitretion.docx
itretion.docx
 
Nested Loops in C.pptx
Nested Loops in C.pptxNested Loops in C.pptx
Nested Loops in C.pptx
 
Programming loop
Programming loopProgramming loop
Programming loop
 
What is loops? What is For loop?
What is loops? What is For loop?What is loops? What is For loop?
What is loops? What is For loop?
 
Control Statement IN C.pptx
Control Statement IN C.pptxControl Statement IN C.pptx
Control Statement IN C.pptx
 
Looping in c++
Looping in c++Looping in c++
Looping in c++
 

Recently uploaded

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactisticshameyhk98
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 

Recently uploaded (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 

Loops in c++ programming language

  • 1. LOOP IN C++: The mechanism through which a statement or set of statement can be executed repeatedly is called loop . The statements that are executed repeatedly are called body of loop. The body of loop can be executed repeatedly for a specified number of times or until the given condition remains true . In c++ there are four types of loop as; 1) For loop 2) while loop 3) Do while loop 4) Nested loop @Muhammad
  • 2. –For loop • The “for” loop is used to execute a statement or set of statements repeatedly for a specific numbers of times • This loop is also known as counter loop. Syntax of for loop For{initialization;condition;increment/decrement} { } Statements; Next statement; @Muhamm
  • 3. The “for”loop is executed as follows; Working of For loop When control enters into the loop 1)First initialization part is executed . It is executed only for the first time 2)After executing initialization part , the condition is evaluated.if it is True,then body of loop is executed. 3)After executing body of loop, increament/decreament part is executed increament/decreament part is last statement of body of “for” loop. . @Muhammad
  • 4. • Our Services • Insert the title of your subtitle Here Flow chart of for loop intialization Body of loop Increament/decreament Next statement True False @Muhamm
  • 5. Example of for loop #include <iostream.h> #include<conio.h> Main(); { Int n; For (n=1;n<=10;n++) cout <<n<<endl; Cout<<“ok”; } @Muhammad
  • 6. While loop • The “while loop ” is conditional loop structure it is used to Execute a statement or set of statement as long as the given condtioin remain true • This loop structure is used when the programmer does not know in advance Syntax of while loop; While (condition) { statement; } Next – statement; @Muhammad
  • 7. The “for”loop is executed as follows; • When a “while ”loop statement is executed the condition is evaluate first • If the condition is true then body of loop is executed • After executing the body of loop, the execution control goes back to t he “while”statement and evaluates the condition again. • If the given condition is still true , the body of loop is executed again. This process is repeated. • When the given condition become false at any stage during • execution ,the loop is terminated. @Muhamma
  • 8. • Our Services • Insert the title of your subtitle Here Flow chart of ”while”loop Body of loop Next statement False True @Muhamm
  • 9. Example of “while ” loop #include<iostream.h> #include<conio.h> Main() { Int num; Num=1; While(num<=15) { If (num%3==0) Cout<<num<<endl; Num=num+1; } } @Muhammad
  • 10. DO WHILE LOOP; • as while loop ,do while loop is also used to execute a state ment or set of statement as long as the given condition rem ains true • The condition comes after the body of loop • The condition is evaluate after executing the body of loop The body of loop must be executed at least once even if The condition is false • Semicolon(;) is given after the while (condition) Syntax of Do while loop; Initialize Do { Body of loop Updation } While (condition) @Muhammad
  • 11. Flow chart of ”Do while”loop Body of loop Next statement False True @Muhammad
  • 12. Example of “Do while ” loop #include<iostream.h> #include<conio.h> Main() { Int i=1; Do { Cout<<i<<“/n”; i++; } While (1<=10); } @Muhamma
  • 13. Nested loop; • A nested loop is a loop within a loop, an inner loop within the body of an outer one. • How this works is that the first pass of the outer loop triggers the inner loop, which executes to completion. Then the second pass of the outer loop triggers the inner loop again. • This repeats until the outer loop finishes Syntax of nested loop; Outer loop { statement (s)-1 Inner-loop { Body of inner loop } Statement (s)-2 } Next – statement; @Muhammad
  • 14. The “nested”loop is executed as follows; • The condition given in outer is evaluated.if condition is true Controls enters inside the body of outer loop.otherwise loop is Terminated. • If body of outer loop contains any statement before the inner loop, it is executed . @Muhammad
  • 15. Example of “nested” loop #include<iostream.h> #include<conio.h> Main() { Int u,i; U=1; While (u<=3) { Cout <<u<<endl; For (i=1;i<=2;i++) Cout <<“I love Pakistann”; U=u+1; } } @Muhamma