Skip to content

Commit 344075d

Browse files
dolmengopherbot
authored andcommitted
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 <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent e602625 commit 344075d

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

doc/go_spec.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6643,7 +6643,7 @@ <h4 id="For_range">For statements with <code>range</code> clause</h4>
66436643
</p>
66446644

66456645
<p>
6646-
The range expression <code>x</code> is evaluated once before beginning the loop,
6646+
The range expression <code>x</code> is evaluated before beginning the loop,
66476647
with one exception: if at most one iteration variable is present and <code>x</code> or
66486648
<a href="#Length_and_capacity"><code>len(x)</code></a> is <a href="#Constants">constant</a>,
66496649
the range expression is not evaluated.

0 commit comments

Comments
 (0)