]> Cypherpunks repositories - gostls13.git/commitdiff
spec: clarify when range expression is evaluated
authorOlivier Mengué <olivier.mengue@gmail.com>
Wed, 1 May 2024 21:18:00 +0000 (23:18 +0200)
committerGopher Robot <gobot@golang.org>
Thu, 2 May 2024 22:43:51 +0000 (22:43 +0000)
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>
doc/go_spec.html

index ac27c1d6c1486d5a5a9939853c02271f0a5e1c63..277cd277758d6c75ac0f6228ba25f4198bdf470b 100644 (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.