The output of the print function differs based on its placement in the code, that much is clear to me.
However I can not conclude why it does that.
1.
fruits = ["apple", "banana", "cherry"]
for x in fruits:
if x == "banana":
continue
print(x)
2.
fruits = ["apple", "banana", "cherry"]
for x in fruits:
if x == "banana":
continue
print(x)
3.
fruits = ["apple", "banana", "cherry"]
for x in fruits:
if x == "banana":
continue
print(x)
Number 1 will output apple
and cherry
while Number 2 will print nothing and Number 3 will print only cherry
.
I do understand that continue
will skip the loop for banana and therefore not print it, yet I"m not sure why 2. print nothing and 3. prints cherry.