Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 15

C++( Loops)

by HASSAN FAROOQ
Loop Structures
A type of control structure that repeats
a statement or set of statements is
known as Looping Structures. It is also
known as iterative structure or
repetitive.
Types of Loops:
While Loop
do…while Loop
for Loop
while loop
Syntax:

_____________________________
while loop
Flow Chart:
While program|counting 1 to 10
#include <iostream>
#include <conio.h> Output:
void main()
1
{
int n;
2
n=1;
3
while (n<=10) 4
{ 5
cout<<n<<endl; 6
n++; 7
}
8
getch();
9
}
10
do..while loop
Syntax:
do..while loop
Flow Chart:
do..While program|counting 10 to 1
#include <iostream>
#include <conio.h> Output:
void main()
10
{
int c;
9
c=10;
8
do 7
{ 6
cout<<n<<endl; 5
c=c-1; 4
}
3
while (c>=1);
2
getch();
}
1
for loop
Syntax:
for loop
Flow Chart:
For loop program|Table of a number
#include <iostream>
#include <conio.h>
Output:
void main() Enter table number: 2
{ Enter length of table: 5
int tab,len,i;
cout<<“Enter table number: ”;
2*1=2
cin>>tab; 2*2=4
cout<<“Enter length of table: ”; 2*3=6
2*4=8
cin>>len;

for(i=1; c<=len; i++) 2*5=10


cout<<tab<<‘’*”<<i<<“=”<<tab*i<<endl;
getch();
}
Nested-for loop
Syntax:
Nested-For loop program
#include <iostream>
#include <conio.h> Output:
void main()
****
****
****
****
****

You might also like