0% found this document useful (0 votes)
22 views1 page

Do While Loop Example - Incrementation While Loop Example For Loop Example - Incrementation

The document contains examples of while, do-while, and for loops in C++. The while and do-while loops demonstrate incrementation, printing numbers from 1 to 5. The first for loop example also prints numbers from 1 to 5 using incrementation. The second for loop example calculates the sum of numbers from 1 to 5 using an accumulator variable to add each value of n to the running total.

Uploaded by

Rhon Dee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views1 page

Do While Loop Example - Incrementation While Loop Example For Loop Example - Incrementation

The document contains examples of while, do-while, and for loops in C++. The while and do-while loops demonstrate incrementation, printing numbers from 1 to 5. The first for loop example also prints numbers from 1 to 5 using incrementation. The second for loop example calculates the sum of numbers from 1 to 5 using an accumulator variable to add each value of n to the running total.

Uploaded by

Rhon Dee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

while loop example do while loop example – incrementation for loop example – incrementation

#include<iostream.h> #include<iostream.h> #include<iostream.h>


#include<conio.h> #include<conio.h> #include<conio.h>
main() main() main()
{ { {
int n; int n; int n;
clrscr(); clrscr(); clrscr();
cout<<"\n while loop example"; cout<<"\n do while loop example - incrementation"; cout<<"\n for loop example - incrementation";
n=1; n=1; for (n=1; n<=5; n++)
while (n<=5) {
{ do { cout<<"\n"<< n <<endl;
cout<<"\n"<< n << endl; cout<<"\n"<< n <<endl; }
return 0;
n++; n++; }
} }
return 0; while (n<=5);
} return 0;
}

for loop example – Accumulator

#include<iostream.h>
#include<conio.h>
main()
{
int n, sum;
clrscr();
cout<<"\n for loop example - accumulator";
sum=0;
for (n=1; n<=5; n++)
{
cout<<"\n"<< n <<endl;
sum=sum+n;
}
cout<<"the sum: "<<sum;

return 0;
}

You might also like