-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloops.cpp
More file actions
74 lines (63 loc) · 1.14 KB
/
loops.cpp
File metadata and controls
74 lines (63 loc) · 1.14 KB
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
71
72
73
74
#include <iostream>
using namespace std;
int main()
{
/*Loops in C++:
There are three types of loops in C++:
1. For loop
2. While Loop
3. do-While Loop
*/
/*For loop in C++*/
int i=1;
cout<<i;
i++;
Syntax for for loop
for(initialization; condition; updation)
{
loop body(C++ code);
}
for (int i = 1; i <= 40; i++)
{
/* code */
cout<<i<<endl;
}
Example of infinite for loop
for (int i = 1; 34 <= 40; i++)
{
/* code */
cout<<i<<endl;
}
/*While loop in C++*/
Syntax:
while(condition)
{
C++ statements;
}
Printing 1 to 40 using while loop
int i=1;
while(i<=40){
cout<<i<<endl;
i++;
}
Example of infinite while loop
int i = 1;
while (true)
{
cout << i << endl;
i++;
}
/* do While loop in C++*/
Syntax:
do
{
C++ statements;
}while(condition);
Printing 1 to 40 using while loop
int i=1;
do{
cout<<i<<endl;
i++;
}while(false);
return 0;
}