This is a creation in Article, where the information may have evolved or changed.
1. Basic knowledge Supplement (pointer, increment decrement statement)
Pointer
Go retains pointers, but unlike other programming languages, pointer operations and the "-to" operator are not supported in go, and direct use of the "." Selector to manipulate the members of the target object
- Operator "&" takes the variable address and uses "*" to indirectly access the target object using the pointer
- The default value is nil and not null
In go, + + and--are used as statements rather than as expressions
1a++//但不能这样:a := a++,只能作为单独的语句独占一行
2.if Judgment Statement
conditional expression without parentheses
Supports an initialization expression (which can be in parallel mode)
The opening brace must be on the same line as the conditional statement or else
Support single-line mode
The variable in the initialization statement is the block level, while the external variable with the same name is hidden
func main(){ 10 if a:=1 { fmt.Println(a) } fmt.Println(a) }//输出为: 1 10
3.for Loop statement
- Go is only for a loop statement keyword, but it supports 3 different forms
//第一种(同其他语言的while true {}):func main() { 1 for { a++ if3{ break } } fmt.Println(a)}//第二种(同其他语言的:while a <= 3 {}): func main() { 1 for3 { a++ } fmt.Println(a)}//第三种:func main() { 1 for03; i++ { a++ } fmt.Println(a)}
- Initialization and stepping expressions can be multiple values
4.switch Selection Statement
There is no need to manually write a break for each case in the go language to prevent the program from continuing to match down. If you want to achieve the purpose of continuing the match, you can use the keyword: fallthrough
funcMain () {A: =1 SwitchA Case 0: FMT. Println ("A=0") Case 1: FMT. Println ("A=1")} FMT. Println (A)}funcMain () {A: =1 Switch{ CaseA >=0: FMT. Println ("A=0")Fallthrough CaseA >=1: FMT. Println ("A=1")} FMT. Println (A)}//At this time the scope of a is only within the switch expressionfuncMain () {SwitchA: =1{ CaseA >=0: FMT. Println ("A=0")Fallthrough CaseA >=1: FMT. Println ("A=1")} FMT. Println (A)}
5. Jump statements
Break, continue, goto mate tags using