Jan Mercl <0xj...@gmail.com> wrote:
> On Sun, Jan 12, 2020 at 10:10 AM Silvan Jegen 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
On Sun, Jan 12, 2020 at 10:10 AM Silvan Jegen 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
On Sun, 2020-01-12 at 10:10 +0100, Silvan Jegen wrote:
> So the declaration of the variables in the for loop itself is in
> outer scope compared to the body of the for loop?
Yes.
> In that case, redeclaring them in the inner scope (== the loop body)
> would not be allowed either, no?
What?
The
Dan Kortschak wrote:
> The gopher operator is allowed to be used because the body of the for
> loop is a new scope. In the second example, the a, b := b, a is not in
> a new scope.
So the declaration of the variables in the for loop itself is in outer
scope compared to the body of the for loop?
The gopher operator is allowed to be used because the body of the for
loop is a new scope. In the second example, the a, b := b, a is not in
a new scope.
On Sun, 2020-01-12 at 09:09 +0100, Silvan Jegen wrote:
> Hi fellow gophers
>
> The following code compiles
>
>
> package main
>
> import (
The range clause introduces a new scope. See this version of your second
example: https://play.golang.org/p/UXI_w6B4DW5
-- Ian
On Sun, 12 Jan 2020, at 8:09 AM, Silvan Jegen wrote:
> Hi fellow gophers
>
> The following code compiles
>
>
> package main
>
> import (
> "fmt"
> )
>
> func
Hi fellow gophers
The following code compiles
package main
import (
"fmt"
)
func main() {
mymap := map[string]int{"a": 1, "b": 2}
for k, v := range mymap {
k, v := k, v
fmt.Printf("k %s, v: %d\n", k, v)
}
}
while this one