1
1
<!--{
2
2
"Title": "The Go Programming Language Specification",
3
- "Subtitle": "Language version go1.23 (June 12 , 2024)",
3
+ "Subtitle": "Language version go1.23 (June 13 , 2024)",
4
4
"Path": "/ref/spec"
5
5
}-->
6
6
@@ -6620,7 +6620,8 @@ <h4 id="For_range">For statements with <code>range</code> clause</h4>
6620
6620
< p >
6621
6621
A "for" statement with a "range" clause
6622
6622
iterates through all entries of an array, slice, string or map, values received on
6623
- a channel, or integer values from zero to an upper limit [< a href ="#Go_1.22 "> Go 1.22</ a > ].
6623
+ a channel, integer values from zero to an upper limit [< a href ="#Go_1.22 "> Go 1.22</ a > ],
6624
+ or values passed to an iterator function's yield function [< a href ="#Go_1.23 "> Go 1.23</ a > ].
6624
6625
For each entry it assigns < i > iteration values</ i >
6625
6626
to corresponding < i > iteration variables</ i > if present and then executes the block.
6626
6627
</ p >
@@ -6633,11 +6634,15 @@ <h4 id="For_range">For statements with <code>range</code> clause</h4>
6633
6634
The expression on the right in the "range" clause is called the < i > range expression</ i > ,
6634
6635
its < a href ="#Core_types "> core type</ a > must be
6635
6636
an array, pointer to an array, slice, string, map, channel permitting
6636
- < a href ="#Receive_operator "> receive operations</ a > , or an integer.
6637
+ < a href ="#Receive_operator "> receive operations</ a > , an integer, or
6638
+ a function with specific signature (see below).
6637
6639
As with an assignment, if present the operands on the left must be
6638
6640
< a href ="#Address_operators "> addressable</ a > or map index expressions; they
6639
- denote the iteration variables. If the range expression is a channel or integer,
6640
- at most one iteration variable is permitted, otherwise there may be up to two.
6641
+ denote the iteration variables.
6642
+ If the range expression is a function, the maximum number of iteration variables depends on
6643
+ the function signature.
6644
+ If the range expression is a channel or integer, at most one iteration variable is permitted;
6645
+ otherwise there may be up to two.
6641
6646
If the last iteration variable is the < a href ="#Blank_identifier "> blank identifier</ a > ,
6642
6647
the range clause is equivalent to the same clause without that identifier.
6643
6648
</ p >
@@ -8676,6 +8681,12 @@ <h4 id="Go_1.22">Go 1.22</h4>
8676
8681
</ li >
8677
8682
</ ul >
8678
8683
8684
+ < h4 id ="Go_1.23 "> Go 1.23</ h4 >
8685
+ < ul >
8686
+ < li > A "for" statement with < a href ="#For_range "> "range" clause</ a > accepts an iterator
8687
+ function as range expression.
8688
+ </ li >
8689
+ </ ul >
8679
8690
< h3 id ="Type_unification_rules "> Type unification rules</ h3 >
8680
8691
8681
8692
< p >
0 commit comments