Complete list of go language keywords

PHPz
Release: 2024-04-07 14:15:01
Original
1118 people have browsed it

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

Complete list of go language keywords

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 execution
  • else: Optional conditional branch
  • for: Loop execution
  • return : Return from the function

Data type related keywords

  • bool: Boolean value
  • string:String
  • int:Integer
  • float64:Floating point number
  • interface{}: Any type
  • map: Key-value pair collection
  • slice: Dynamic size array

Other keywords

  • break: Exit the loop
  • continue: Jump to the next part of the loop An iteration
  • defer: Defer function call execution until function exit
  • go: Execute function concurrently
  • select: 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)
    }
}
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!