Go — declared and not used error, when I think I have done so to the variable

前端 未结 2 721
梦如初夏
梦如初夏 2021-01-12 11:11

What\'s wrong with this code?

package main

import \"fmt\"

// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func(         


        
2条回答
  •  Happy的楠姐
    2021-01-12 12:14

    You declared a variable named prev and then never used it.

    Specifically, you said prev := temp. This is creating a new local variable in the current scope named prev. I assume you meant to just say prev = temp, which modifies the prev variable inherited from the surrounding scope. Similarly you probably meant to say curr = curr + prev on the previous line, instead of using :=.

提交回复
热议问题