Exit

os.exit(code) terminates the script immediately with the given integer exit code. Code 0 means success; any non-zero value signals failure.

fmt := import("fmt")
os := import("os")

fmt.println("starting")
for i := 0; i < 3; i++ {
    fmt.println("step ", i)
}
os.exit(0)

fmt.println("this will not print")

try it

starting
step 0
step 1
step 2
this will not print
loading…