Learn
Just like with while
, for
loops may have an else
associated with them.
In this case, the else
statement is executed after the for
, but only if the for
ends normally—that is, not with a break
. This code will break
when it hits 'tomato'
, so the else
block won’t be executed.
Instructions
1.
Click Run to see how for
and else
work together.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.