for循环的异常行为

I sure hope this is something simple. When I grab information from within an if statement that is inside of a for loop it is not carried to outside of the for loop. I can print the information from within the if statement just fine and then lose it afterwards. Am I missing something? Coming from Python I have never experienced this before.

func main() {
    var neededinfo string
    for _, slice := range info_slices {
        // Get information out of slices
        if strings.Contains(slice, "indicator ") {
            neededinfo := string(ExeSH("echo '" + slice + "' | awk '{ print $4 }'"))
            neededinfo = neededinfo[1:len(neededinfo)-2]
            fmt.Println(neededinfo) // Returns my information
        }
    }
    fmt.Println(neededinfo) // Returns nothing
}

Most likely is the fact that you are overwriting the neededinfo variable

func main() {
    var neededinfo []string
    for _, slice := range info_slices {
        // Get information out of slices
        if strings.Contains(slice, "indicator ") {
            response := string(ExeSH("echo '" + slice + "' | awk '{ print $4 }'"))
            neededinfo = append(neededinfo, response[1:len(response)-2]
        }
    }
    fmt.Println(neededinfo) 
}