IF
if condition:
Do this…
elif condition:
Do That
else:
Do That
Shorthand
if condition: do that
For Loops
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
if x == "banana":
break
fruits = ["apple", "banana", "cherry"]
for x in fruits:
if x == "banana":
continue
print(x)
for x in range(6):
print(x)
for x in range(2, 30, 3):
print(x)
for x in range(6):
print(x)
else:
print("Finally finished!")
for x in [0, 1, 2]:
pass
While Loops
i = 1
while i < 6:
print(i)
i += 1
i = 1
while i < 6:
print(i)
if i == 3:
break
i += 1
i = 0
while i < 6:
i += 1
if i == 3:
continue
print(i)
i = 1
while i < 6:
print(i)
i += 1
else:
print("i is no longer less than 6")