-
Notifications
You must be signed in to change notification settings - Fork 0
/
8.loops in cpp.cpp
70 lines (60 loc) · 1.12 KB
/
8.loops in cpp.cpp
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
using namespace std;
int main()
{
// there are 3 types of loops availble in cpp
// for loop
// while loop
// do-while
// structure of for loop
/*
for(initialization ; condition; updation)
{
code statements
}
*/
cout << "printing the for loop ";
for (int i = 0; i < 5; i++)
{
/* code */
cout << i << ":"
<< "a" << endl;
}
// structure of while loop
/*
initialization ;
while (condition)
{
code statements
updation;
}
*/
cout << "printing the while loop";
int c = 0;
while (c < 5)
{
/* code */
cout << c << ":"
<< "a" << endl;
// i++ or i = i+1; both are same
c++;
}
// structure of Do-while loop
/*
initialization ;
do
{
statements
updation;
} while (condition);
*/
cout << "printing do-while loop";
int k = 0;
do
{
cout << k << ":"
<< "a" << endl;
k = k + 1;
} while (k < 5);
return 0;
}