diff options
author | Olivier Mengué <olivier.mengue@gmail.com> | 2024-05-01 23:18:00 +0200 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2024-05-02 22:43:51 +0000 |
commit | 344075d9369103a453add5acf3cb6d68057e8423 (patch) | |
tree | 1f4cc1d2eb0cd04d929e41533c6c8f767d432f42 | |
parent | e602625c5e65da607b99f72082dd60ff70cafe04 (diff) | |
download | go-344075d9369103a453add5acf3cb6d68057e8423.tar.gz go-344075d9369103a453add5acf3cb6d68057e8423.zip |
spec: clarify when range expression is evaluated
Clarify that the range expression of a "for" loop is called *just* once to
rule out that it might be re-evaluated after each iteration.
Change-Id: Iedb61cd29e5238ac0168b8ac01c34d6208cc4312
Reviewed-on: https://go-review.googlesource.com/c/go/+/582775
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
-rw-r--r-- | doc/go_spec.html | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/doc/go_spec.html b/doc/go_spec.html index ac27c1d6c1..277cd27775 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -6643,7 +6643,7 @@ the range clause is equivalent to the same clause without that identifier. </p> <p> -The range expression <code>x</code> is evaluated once before beginning the loop, +The range expression <code>x</code> is evaluated before beginning the loop, with one exception: if at most one iteration variable is present and <code>x</code> or <a href="#Length_and_capacity"><code>len(x)</code></a> is <a href="#Constants">constant</a>, the range expression is not evaluated. |