Middle+
How soon are you ready to leave?
sobes.tech AI
Answer from AI
In Go, you can quickly exit a function or program using the return keyword for functions and os.Exit() to terminate the entire program.
Example of quick exit from a function:
func process(value int) {
if value < 0 {
return // exit quickly if the condition is not met
}
// further logic
}
To immediately terminate the program with a return code:
import "os"
func main() {
// ...
os.Exit(1) // terminate the program with code 1
}
Go also has panic, which interrupts execution, but it is more for errors rather than normal exits.