Add for loop to loops demo
This commit is contained in:
parent
8beeb25522
commit
11da8437fa
|
@ -11,4 +11,20 @@ while number <= 10:
|
||||||
print(f"Number: {number}")
|
print(f"Number: {number}")
|
||||||
number = number + 1
|
number = number + 1
|
||||||
|
|
||||||
|
# The range(start, end) function returns
|
||||||
|
# numbers starting with "start" and ending
|
||||||
|
# one number before "end".
|
||||||
|
# range(0, 10) will return numbers from 0 to 9
|
||||||
|
|
||||||
|
# This is a "for" loop. For loops are used to
|
||||||
|
# iterate over lists or other collections of data.
|
||||||
|
# To iterate means to walk through a set of data
|
||||||
|
# one element at a time. A for loop lets you walk
|
||||||
|
# through a collection of data and do something
|
||||||
|
# with each element of that collection.
|
||||||
|
print("Numbers:", end='')
|
||||||
|
for num in range(0, 10):
|
||||||
|
print(f" {num}", end='')
|
||||||
|
print()
|
||||||
|
|
||||||
print()
|
print()
|
Loading…
Reference in New Issue
Block a user