Merge pull request #12381 from acoglio/patch-4

Improve description of break/continue restrictions.
This commit is contained in:
chriseth 2021-12-14 18:52:52 +01:00 committed by GitHub
commit 55dd953cc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -541,10 +541,24 @@ evaluate to zero values.
In all other situations, expressions have to evaluate to exactly one value.
The ``continue`` and ``break`` statements can only be used inside loop bodies
and have to be in the same function as the loop (or both have to be at the
top level). The ``continue`` and ``break`` statements cannot be used
in other parts of a loop, not even when it is scoped inside a second loop's body.
A ``continue`` or ``break`` statement can only be used inside the body of a for-loop, as follows.
Consider the innermost loop that contains the statement.
The loop and the statement must be in the same function, or both must be at the top level.
The statement must be in the loop's body block;
it cannot be in the loop's initialization block or update block.
It is worth emphasizing that this restriction applies just
to the innermost loop that contains the ``continue`` or ``break`` statement:
this innermost loop, and therefore the ``continue`` or ``break`` statement,
may appear anywhere in an outer loop, possibly in an outer loop's initialization block or update block.
For example, the following is legal,
because the ``break`` occurs in the body block of the inner loop,
despite also occurring in the update block of the outer loop:
.. code-block:: yul
for {} true { for {} true {} { break } }
{
}
The condition part of the for-loop has to evaluate to exactly one value.