forked from vipinkjonwal/CPP_Coding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops.cpp
More file actions
45 lines (37 loc) · 855 Bytes
/
loops.cpp
File metadata and controls
45 lines (37 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]){
//for loop.
cout << "\n\tFOR LOOP\n";
int forSum = 0;
for (int i = 0; i < 10; ++i){
cout << i << "th iteration.\n";
forSum = forSum + i;
if (forSum < 25){
continue;
}
else{
cout << "Sum is " << forSum << endl << endl;
}
}
cout << "Sum is " << forSum << endl << endl;
//while loop.
cout << "\n\tWHILE LOOP\n";
int myCounter = 10;
int whileSum = 0;
while (myCounter > 0){
cout << "Value of counter is " << myCounter << endl;
whileSum = whileSum + myCounter;
myCounter--;
cout << "Sum is " << whileSum << endl << endl;
}
cout<< "Sum is "<< whileSum << endl;
//do-while loop
cout << "\n\tDO-WHILE LOOP\n";
int doWhile = 3;
do{
cout << "Value of counter is " << doWhile << endl;
doWhile--;
}while(doWhile!=0);
return 0;
}