Skip to content

Commit

Permalink
spec: clarify when a range expression is evaluated
Browse files Browse the repository at this point in the history
If the range expression is a numeric constant, the
range expression is also not evaluated.

Change-Id: I97201e5c136d3d1a87ed1500b19b7199b30bc9ff
Reviewed-on: https://go-review.googlesource.com/c/go/+/581298
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
  • Loading branch information
griesemer authored and gopherbot committed Apr 25, 2024
1 parent 4351af6 commit db5f2b4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions doc/go_spec.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
"Subtitle": "Language version go1.22 (Feb 6, 2024)",
"Subtitle": "Language version go1.22 (April 24, 2024)",
"Path": "/ref/spec"
}-->

Expand Down Expand Up @@ -6644,8 +6644,8 @@ <h4 id="For_range">For statements with <code>range</code> clause</h4>

<p>
The range expression <code>x</code> is evaluated once before beginning the loop,
with one exception: if at most one iteration variable is present and
<code>len(x)</code> is <a href="#Length_and_capacity">constant</a>,
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.
</p>

Expand Down

0 comments on commit db5f2b4

Please sign in to comment.