@@ -4377,9 +4377,15 @@ <h3 id="For_statements">For statements</h3>
4377
4377
</ p >
4378
4378
4379
4379
< p >
4380
- The range expression is evaluated once before beginning the loop
4381
- except if the expression is an array, in which case, depending on
4382
- the expression, it might not be evaluated (see below).
4380
+ The range expression is evaluated once before beginning the loop,
4381
+ with one exception. If the range expression is an array or a pointer to an array
4382
+ and only the first iteration value is present, only the range expression's
4383
+ length is evaluated; if that length is constant by definition
4384
+ (see §< a href ="#Length_and_capacity "> Length and capacity</ a > ),
4385
+ the range expression itself will not be evaluated.
4386
+ </ p >
4387
+
4388
+ < p >
4383
4389
Function calls on the left are evaluated once per iteration.
4384
4390
For each iteration, iteration values are produced as follows:
4385
4391
</ p >
@@ -4396,8 +4402,8 @@ <h3 id="For_statements">For statements</h3>
4396
4402
< ol >
4397
4403
< li >
4398
4404
For an array, pointer to array, or slice value < code > a</ code > , the index iteration
4399
- values are produced in increasing order, starting at element index 0. As a special
4400
- case, if only the first iteration variable is present, the range loop produces
4405
+ values are produced in increasing order, starting at element index 0.
4406
+ If only the first iteration variable is present, the range loop produces
4401
4407
iteration values from 0 up to < code > len(a)</ code > and does not index into the array
4402
4408
or slice itself. For a < code > nil</ code > slice, the number of iterations is 0.
4403
4409
</ li >
0 commit comments