Go Keywords

Last Updated : 26 Jun, 2026

Keywords are reserved words that have predefined meanings in the Go language. They are used to define the structure and behaviour of a program, such as declaring variables, creating functions, controlling program flow and importing packages.

Since keywords are reserved by the language, they cannot be used as identifiers for variables, functions, constants or other program elements.

Go
package main
import "fmt"

func main() {
	var name = "David"
	fmt.Println(name)
}

Output
David

Explanation:

  • package defines the package name.
  • import includes external packages in the program.
  • func is used to define a function and var is used to declare a variable.

Using a Keyword as an Identifier

Keywords cannot be used as variable names or other identifiers.

Go
package main

func main() {
	var default = "Go"
}

Output

ERROR!
# command-line-arguments
/tmp/p7MPl0eEgf/main.go:4:6: syntax error: unexpected default, expected name

Explanation: default is a Go keyword, so it cannot be used as a variable name.

List of Go Keywords

Go currently has 25 keywords:

breakcasechanconstcontinue
defaultdeferelsefallthroughfor
funcgogotoifimport
interfacemappackagerangereturn
selectstructswitchtypevar

Commonly Used Keywords

The following keywords are frequently used in Go programs:

KeywordPurpose
packageDefines the package of the program
importImports packages
funcDeclares a function
varDeclares variables
constDeclares constants
ifExecutes code based on a condition
forCreates loops
switchSelects one of multiple code blocks
returnReturns a value from a function
typeCreates custom data types

Example: This example demonstrates how multiple Go keywords work together in a program.

Go
package main
import "fmt"

func main() {
	const language = "Go"

	for i := 1; i <= 3; i++ {
		if i == 2 {
			fmt.Println(language)
		}
	}
}

Output
Go

Explanation:

  • const creates a constant named language.
  • for creates a loop and if checks a condition.
  • fmt.Println() displays the output.

Keywords vs Identifiers

Keywords and identifiers may look similar, but they serve different purposes in a Go program. The table below highlights the main differences between them.

KeywordsIdentifiers
Reserved by the languageCreated by the programmer
Cannot be used as namesUsed to name program elements
Examples: if, for, funcExamples: name, age, printData

Example: This example shows the difference between a Go keyword and an identifier.

Go
package main
import "fmt"

func main() {
	var age = 25
	fmt.Println(age)
}

Output
25

Explanation: Here, var is a keyword, while age is an identifier.

Comment

Explore