Python für Schleife
for i in range(1.10):
print(i)
#output: 1,2,3,4,5,6,7,8,9,10
AMXX
for i in range(1.10):
print(i)
#output: 1,2,3,4,5,6,7,8,9,10
A for loop iterates through an iterable, may that be an array, a string, or a range of numbers
#Example:
myArr = ["string 1", "string 2"]
for x in myArr:
print(x)
#Returns "string 1", "string 2". In here the x is an iterator and does not need to be defined.
#for loop without passing a argument
for _ in range(3):
print("Hello")
# Range:
for x in range(5):
print(x) # prints 0,1,2,3,4
# Lists:
letters = ['a', 'b', 'c']
for letter in letters:
print(letter) # prints a, b, c
# Dictionaries:
letters = {'a': 1, 'b': 2, 'c': 3}
for letter, num in letters.items():
print(letter, num) # prints a 1, b 2, c 3
for number in range(10):
print(number)
x = None # you can change this
y = None # you can change this
while x < y:
#do something
break