Home >Backend Development >Golang >Complete list of go language keywords
The keywords of Go language are: basic keywords: const, func, type, var, if, else, for, return Data type related keywords: bool, string, int, float64, interface{}, map, slice Other keywords: break, continue, defer, go, select, range
Go Language Keyword Guide
The Go language is A concise, efficient programming language whose keywords are used to control program flow, data types, and other language features. Mastering these keywords is crucial to understanding and writing Go code.
Basic keywords
#const
: define a constant func
: define A function type
: defines a type var
: defines a variable if
: Conditional executionelse
: Optional conditional branchfor
: Loop executionreturn
: Return from the function Data type related keywords
bool
: Boolean valuestring
:Stringint
:Integerfloat64
:Floating point number interface{}
: Any typemap
: Key-value pair collectionslice
: Dynamic size arrayOther keywords
break
: Exit the loopcontinue
: Jump to the next part of the loop An iterationdefer
: Defer function call execution until function exitgo
: Execute function concurrentlyselect
: Wait for events in multiple channels range
: Traverse elements in the sequence Practical case
The following is a simple Go code example showing several keywords:
func main() { const name string = "John Doe" var age int = 30 if age > 21 { fmt.Println(name + " is an adult.") } else { fmt.Println(name + " is a minor.") } for i := 0; i < 5; i++ { fmt.Println(i) } }
In this example, we use const
to define a constant string name
, var
to define an integer variable age
, if
and else
to execute conditional branches, for
to execute the loop.
The above is the detailed content of Complete list of go language keywords. For more information, please follow other related articles on the PHP Chinese website!