-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLoops
99 lines (76 loc) · 1.59 KB
/
Loops
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <iostream>
using namespace std;
int main()
{
// LOOPS (WHILE, DO WHILE AND FOR LOOP):
// while:
/* Syntax of While Loop:
while(condition)
{
loop body(C++ code);
}
*/
int index = 0;
while (index < 34)
{
cout << "We are at index number " << index << endl;
index = index + 1;
}
cout << endl;
// do while (will execute atleast once, no matter if the condition is true or not):
/* Syntax of do-while Loop:
do
{
C++ code;
}
while(condition)
{
loop body(C++ code)
}
*/
do
{
cout << "\nWe are at index number " << index << endl;
index = index + 1;
}
while (index > 3538);
{
cout << "We are at index number " << index << endl;
index = index + 1;
}
cout << endl;
// for loop:
/* Syntax of For Loop:
for(initialization;condition;updation)
{
loop body(C++ code);
}
*/
for (int i = 0; i <= 34; i++)
{
cout << "\nThe value of i is: " << i << endl;
}
// Generating Table:
int i = 1;
int num;
cout<<"Enter the number "<<endl;
cin>>num;
// do while
do
{
cout << num <<" * " << i << " = " << (num * i) << endl;
i++;
} while (i <= 10);
// for loop
for (i = 1; i <= 10; i++)
{
cout << num << " * " << i << " = " << (num * i) << endl;
}
// while loop
while (i <= 10)
{
cout << num << " * " << i << " = " << (num * i) << endl;
i++;
}
return 0;
}