This repository has been archived by the owner on Nov 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloops.cpp
62 lines (52 loc) · 1.39 KB
/
loops.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
#include <iostream>
#include <vector>
auto loop_1() -> void {
auto numbers = std::vector<int>{1, 2, 3, 4, 5};
auto counter = 0ul;
while (counter < numbers.size()) {
std::cout << numbers[counter] << std::endl;
++counter;
}
}
auto loop_2() -> void {
auto numbers = std::vector<int>{1, 2, 3, 4, 5};
for (auto i = 0ul; i < numbers.size(); ++i) {
std::cout << numbers[i] << std::endl;
}
}
auto loop_3() -> void {
auto numbers = std::vector<int>{1, 2, 3, 4, 5};
for (auto number : numbers) {
std::cout << number << std::endl;
}
}
auto loop_4() -> void {
auto numbers = std::vector<int>{1, 2, 3, 4, 5};
for (auto& number : numbers) {
number = 0;
}
for (auto const& number : numbers) {
std::cout << number << std::endl;
}
// {0, 0, 0, 0, 0}
}
auto loop_5() -> void {
auto matrix = std::vector<std::vector<int>>{{1, 2, 3, 4, 5}, {0, 0, 0, 0, 0}};
for (auto row : matrix) {
//
}
}
auto loop_6() -> void {
auto matrix = std::vector<std::vector<int>>{{1, 2, 3, 4, 5}, {0, 0, 0, 0, 0}};
for (auto& row : matrix) {
// row is a std::vector<int> reference that can be changed
(void)row;
}
for (auto const& row : matrix) {
// row is a const std::vector<int> reference that cannot be changed
(void)row;
}
}
auto main() -> int {
return 0;
}