-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrol.cpp
More file actions
109 lines (96 loc) · 2.17 KB
/
control.cpp
File metadata and controls
109 lines (96 loc) · 2.17 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
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
100
101
102
103
104
105
106
107
108
109
//
// Created by zing on 3/23/2020.
//
#include <iostream>
using namespace std;
void if_and_else(int x) {
if (x > 0)
cout << "x is positive" << endl;
else if (x < 0)
cout << "x is negative" << endl;
else
cout << "x is 0" << endl;
}
void while_loop() {
cout << "=============while_loop==============" << endl;
int n = 10;
while (n > 0) {
cout << n << "\t";
--n;
}
cout << "over!" << endl;
}
void do_while_loop() {
cout << "=============do_while_loop==============" << endl;
int i = 10;
do {
cout << i << "\t";
i--;
} while (i > 0);
cout << endl;
// do {
// cout << "Enter text: ";
// getline(cin, str);
// cout << "You entered: " << str << '\n';
// } while (str != "goodbye");
}
void for_loop() {
cout << "=============for_loop==============" << endl;
for (int n = 10; n > 0; n--) {
cout << n << ", ";
}
cout << "over" << endl;
}
void range_loop() {
cout << "=============range_loop==============" << endl;
string str{"Hello!"};
for (char c : str) {
cout << "[" << c << "]";
}
cout << '\n';
}
void break_loop() {
cout << "=============break_loop==============" << endl;
for (int n = 10; n > 0; n--) {
if (n == 5) continue;
cout << n << ", ";
}
cout << "liftoff!\n";
}
void continue_loop() {
cout << "=============continue_loop==============" << endl;
for (int n = 10; n > 0; n--) {
if (n == 5) continue;
cout << n << ", ";
}
cout << "liftoff!\n";
}
void goto_loop() {
cout << "=============goto_loop==============" << endl;
int n = 10;
label:
cout << n << ", ";
n--;
if (n > 0) {
goto label;
}
cout << "liftoff!\n";
}
void switch_case(int x) {
switch (x) {
case 1:
cout << "x is 1" << endl;
break;
case 2:
cout << "x is 2" << endl;
break;
case 3:
case 4:
case 5:
case 6:
cout << "x is more than 2;less than 7" << endl;
break;
default:
cout << "value of x unknown" << endl;
}
}