The limited scope of local variables

Report a typo

Below you will see the code of a Go program. Please select in what code blocks/statements the local variable food can be accessed:

package main

import "fmt"

func main() {
    for {
        var food string
        fmt.Println("Hello! please enter an emoji of any food type:")
        fmt.Scanln(&food)

        if food == "🍏" {
            fmt.Println(food, "belongs to the FRUIT group!")
            break
        } else if food == "🥦" {
            fmt.Println(food, "belongs to the VEGETABLE group!")
            break
        } else if food == "🍖" {
            fmt.Println(food, "belongs to the MEAT group!")
            break
        } else {
            fmt.Println(food, "is not food!")
            break
        }
    }
}
Select one or more options from the list
___

Create a free account to access the full topic