Jan Mercl <0xj...@gmail.com> wrote: > On Sun, Jan 12, 2020 at 10:10 AM Silvan Jegen <s.je...@gmail.com> wrote: > > > So the declaration of the variables in the for loop itself is in outer > > scope compared to the body of the for loop? > > The outer scope begins immediately after the keyword "for". The inner > one is an ordinary block scope and it begins immediately after the > '{'.
Ah, I see. > > In that case, redeclaring them > > in the inner scope (== the loop body) would not be allowed either, no? > > This is valid: { a := 42; f(a) { a := 24; f(a) }} Right, that makes sense! So my confusion stemmed from me not realizing that the variable declaration in the range clause forms its own scope while the for body constitutes another one. I assumed they belonged in the same scope. So the spec seems fine. Thanks to you and Dan for clearing that up for me! Cheers, Silvan -- 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/2YH00XKBNL6QF.26M7JWLHO8QO4%40homearch.localdomain.