Skip to content
Permalink
874e7d5550
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
39 lines (37 sloc) 1 KB
# example-6.py first example
# Showing complex nested loops with else statements
number = ["3", "2", "1", "100"]
adjective = ["red", "big", "tasty"]
fruits = ["apple", "banana", "cherry"]
count = 0
for x in number:
for y in adjective:
for z in fruits:
count += 1
print(x, y, z)
else:
print("inside loop!")
else:
print("inner loop")
else:
print("outside loop!")
print(count)
print(len(number) * len(adjective) * len(fruits))
# example-6.py second example
# Showing broken complex nested loops with else statements
number = ["3", "2", "1", "100"]
adjective = ["red", "big", "tasty"]
fruits = ["apple", "banana", "cherry"]
count = 0
for x in number:
for y in adjective:
for z in fruits:
break
else:
print("inside loop!")
else:
print("inner loop")
else:
print("outside loop!")
print(count)
print(len(number) * len(adjective) * len(fruits))