else
` statement in a `for
` loop :# Else in for loop
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
else:
print("No more fruits left.")
print("Done.")
apple
banana
cherry
No more fruits left.
Done.
for
` loop to iterate over a list of fruits. Inside the loop, we use the `print()
` function to print each fruit.else
` statement, which prints the message "No more fruits left
." print()
` statement outside the loop, which prints the message "Done
."else
` statement in a `for
` loop to execute a block of code after the loop completes. The `else
` block will only execute if the loop completes all iterations without encountering a `break
` statement.