From d17f7206ad7ac3e40fc253fa3ece8c3a5eaba718 Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Tue, 7 Dec 2021 23:07:19 -0800 Subject: [PATCH] Improve description of break/continue restrictions. This is as discussed on Element, with enhancements discussed with @cameel. --- docs/yul.rst | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/docs/yul.rst b/docs/yul.rst index 219905cd5..60a2da5b9 100644 --- a/docs/yul.rst +++ b/docs/yul.rst @@ -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.