Go — declared and not used -
what's wrong code?
package main import "fmt" // fibonacci function returns // function returns int. func fibonacci() func() int { prev := 0 curr := 1 homecoming func() int { temp := curr curr := curr + prev prev := temp homecoming curr } } func main() { f := fibonacci() := 0; < 10; i++ { fmt.println(f()) } }
prog.go:13: prev declared , not used
you declared variable named prev
, never used it.
specifically, said prev := temp
. creating new local variable in current scope named prev
. assume meant prev = temp
, modifies prev
variable inherited surrounding scope. meant curr = curr + prev
on previous line, instead of using :=
.
go
No comments:
Post a Comment