Skip to content

Control Flow

Python supports the usual logical conditions from mathematics.

a = 33
b = 200
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")

A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).

fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)

With the while loop we can execute a set of statements as long as a condition is true.

i = 1
while i < 6:
print(i)
i += 1