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 loop ends without executing the break
? We are forced to assert that there does not exist even one item that triggered the break
. DeMorgan's Law tells us that a not exists condition can be restated as a for all condition: ¬∃xB(x) ≡ ∀x ¬B(x). In this formula, B(x) is the condition on the if
statement that includes the break
. If we never found B(x), then for all items ¬B(x) was true
. This shows some of the symmetry...