Go by Example: Exit

In Go, you can use the os.Exit function to exit the program immediately with a specific status code.

Here’s an example:

package main

import (

func main() {
	// Exit with status code 3

The status code can be any integer value, and it’s typically used to indicate the status of the program. A status code of 0 indicates success, while non-zero status codes indicate an error. The exact meaning of the status codes depends on the program and the conventions in use.


Leave a Reply

Your email address will not be published. Required fields are marked *