-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnested_loops.py
More file actions
38 lines (24 loc) · 925 Bytes
/
nested_loops.py
File metadata and controls
38 lines (24 loc) · 925 Bytes
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
# Loop within another loop
# Outer loop, inner loop
# range()
# used to generate sequence of numbers
# start, stop, step
# START: optional; default start is 0, unless specified
# STOP: required; number specifying postion to stop (exclusive)
# STEP: optional; default skip is 1, number specifying the amount to skip
# # Prints 0 - 2
# for x in range(3):
# print(x)
# # Prints 1 - 3
# for x in range(1, 4):
# print(x)
# # By default print will "print" on a new line each iteration
# # You can change this using end=""
# for a in range(3):
# for b in range(4):
# print(b, end=" ") # prints on the same line separated by a single space
# print("")
# step can also be used to generate a sequence that counts down
# in this case, you will need to reverse the start and stop values, and specify a negative step
for x in range(10, -4, -2):
print(x)