On Fri, Mar 18, 2022 at 12:43 PM Jochen Voss <jochen.v...@gmail.com> wrote: > The spec at https://go.dev/ref/spec#For_range says > > "The range expression x is evaluated once before beginning the loop, with one > exception: if at most one iteration variable is present and len(x) is > constant, the range expression is not evaluated." > > What does the second half of this sentence mean? > > My guess was that this says that in "for i := range [3]int{1, 2, f()} ..." > the function f is not called, but I quick experiment shows that this guess is > wrong, see https://go.dev/play/p/MXqH_C7mllx .
I think the specs are correct: https://go.dev/play/p/yFlD98R8tNg -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAA40n-ViA7HHjZwqD9a_Q2UK%3D1YuGbOB-qi4HVij4itAJ%3DoZ2A%40mail.gmail.com.