Avoiding a potential problem with break statements
The common way to understand a for
statement is that it creates a for all condition. At the end of the statement, we can assert that, for all items in a collection, some processing has been done.
This isn't the only meaning for a for
statement. When we introduce the break
statement inside the body of a for
, we change the semantics to there exists. When the break
statement leaves the for
(or while
) statement, we can assert only that there exists at least one item that caused the statement to end.
There's a side issue here. What if the for
statement ends without executing break
? Either way, we're at the statement after the for
statement.
The condition that's true upon leaving a for
or while
statement with a break
can be ambiguous. Did it end normally? Did it execute break
? We can't easily tell, so we'll provide a recipe that gives us some design guidance.
This can become an even bigger...