Skip to content

Commit

Permalink
spec: clarify when range expression is evaluated
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
dolmen authored and gopherbot committed May 2, 2024
1 parent e602625 commit 344075d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion doc/go_spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -6643,7 +6643,7 @@ <h4 id="For_range">For statements with <code>range</code> clause</h4>
</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.
Expand Down

0 comments on commit 344075d

Please sign in to comment.