Why does the 'else' statement only print out its string once? surely it should do it for each time a fruit isn't a tomato?

Why does the ‘else’ statement only print out its string once? surely it should do it for each time a fruit isn’t a tomato?Change it up

Hi @jjhiggins97,

The else block header is aligned with the for loop header, rather than with the if block header. Accordingly, the else block is associated with the for loop, and executes once, after the for loop has performed all its iterations. However, if the for loop is interrupted by the execution of a break statement, then it does not perform all its iterations, and the associated else block does not execute at all.

1 Like

Fab! Thanks so much!

1 Like