-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path82_looping.txt
More file actions
76 lines (42 loc) · 1.22 KB
/
82_looping.txt
File metadata and controls
76 lines (42 loc) · 1.22 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
Section 09: Looping
------------------------------------------------------------------------------
Iteration
- The third basic building block of programming
+ sequence, selection, iteration
- Iteration or repetition
- Allows the execution of a statement or block
of statements repeatedly
- Loops are made up of a loop condition and the
body which contains the statements to repeat
Some Typical use-cases
Execute a loop:
+ a specific number of times
+ for each element in a collection
+ while a specific condition remains
true
+ until a specific condition becomes
false
+ until we reach the end of some input
stream
+ forever (ex: operating systems)
+ many, many more
C++ Looping Constructs
- for loop
+ iterate a specific number of times
- Range-based for loop
+ one iteration for each element in a
range or collection
- while loop
+ iterate while a condition remains
true
+ stop when the condition becomes
false
+ check the condition at the beginning
of every iteration
- do-while loop
+ iterate while a condition remains
true
+ stop when the condition becomes
false
+ check the condition at the end of
every iteration