返回菜单语言GO

0 menu go

我有一个菜单选项有两个选项:add和substract.当我选择一个它运行正常但程序关闭.我想知道在操作结束后再选择另一个菜单后如何返回菜单

package main

import (
    "fmt"
)

func main() {
    var n1, n2, s, r float64
    var op, ns int

    fmt.Println("\n\tWelcome")
    fmt.Println("Chose an option")
    fmt.Println("1.-Add")
    fmt.Println("2.-Substract")
    fmt.Scan(&op)

    if op == 1 {

        fmt.Printf("\n\tAdd")
        fmt.Printf("\nHow many numbers you add? ")
        fmt.Scan(&ns)
        if ns <= 1 {
            fmt.Print("You can not add just a number")

        } else {
            for i := 0; i < ns; i++ {
                fmt.Printf("\nType the number %d: ", i+1)
                fmt.Scan(&n1)
                s += n1
            }

            fmt.Println("\nThe sum is: ", s)
            //How to return to the menu?
        }

    } else if op == 2 {
        fmt.Printf("\n\tSubtraction")
        fmt.Printf("\nType the first number: ")
        fmt.Scan(&n1)
        fmt.Printf("\nType the second number: ")
        fmt.Scan(&n2)
        r = n1 - n2
        fmt.Println("\nSubstraction is: ", r)
    }
}
Run Code Online (Sandbox Code Playgroud)

Ask*_*sen 5

把整个东西包起来

for {

}
Run Code Online (Sandbox Code Playgroud)

使用break退出循环或continue返回到顶部.