1
0
mirror of https://github.com/golang/go synced 2024-11-22 05:14:40 -07:00

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>
This commit is contained in:
Olivier Mengué 2024-05-01 23:18:00 +02:00 committed by Gopher Robot
parent e602625c5e
commit 344075d936

View File

@ -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.