3 // Copyright 2015 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Ensure that zeroing range loops have the requisite side-effects.
17 // When n == 0, i is untouched by the range loop.
18 // Picking an initial value of -1 for i makes the
19 // "want" calculation below correct in all cases.
25 if want := n - 1; i != want {
26 fmt.Printf("index after range with side-effect = %d want %d\n", i, want)
31 // i is shadowed here, so its value should be unchanged.
35 if want := n + 1; i != want {
36 fmt.Printf("index after range without side-effect = %d want %d\n", i, want)
40 // Index variable whose evaluation has side-effects
47 for a[f()] = range s {
50 if want := n * 2; x != want {
51 fmt.Printf("index function calls = %d want %d\n", x, want)
55 // Range expression whose evaluation has side-effects
58 for i := range b[f()] {
61 if want := n + 1; x != n+1 {
62 fmt.Printf("range expr function calls = %d want %d\n", x, want)