This is a creation in Article, where the information may have evolved or changed.
Pointer
Go retains pointers, but unlike other programming languages, pointer arithmetic and the "-to" operator are not supported in go, but directly with "." Selectors to manipulate the members of the pointer 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
Increment Decrement statement
In go, + + and – are used as statements rather than as expressions.
SELECT statement Switch
- You can use any type or expression as a conditional statement
- No write break is required, once the condition meets automatic termination
- If you want to continue with the next case, you need to use the Fallthrough statement
- Supports an initialization expression (which can be in parallel), and the right side needs to be well-divided
- The left brace must be on the same line as the conditional statement
12345678910111213141516171819202122232425262728293031323334353637 |
func main() {A: =1SwitchA Case 0: FMT. Println ("A=0") Case 1: FMT. Println ("A=1")}fmt. Println (A)} func main() {A: =1Switch{ CaseA >=0: FMT. Println ("A=0")Fallthrough CaseA >=1: FMT. Println ("A=1")}fmt. Println (A)} func main() {SwitchA: =1; { CaseA >=0: FMT. Println ("A=0")FallthroughCAEs a >=1: FMT. Println ("A=1")}} |
Jump Statement goto Break Continue
- Three statements can be used in conjunction with labels using the
- tag name to be case-sensitive, which would cause a compilation error if not used
- break and continue mate tags can be used to jump out of a multi-layered loop
- goto is the adjustment execution position, The result of matching labels with the other 2 statements is not the same
1234567891011121314151617181920212223 242526 |
func main () {label:for {for i : = 1 , I < 10 ; i++ {if i > Span class= "number" >2 {break label}else {fmt. Println (i)}}}}func main () {label:for i: = 0 ; i < Span class= "number" >10 ; i++ {for {fmt. Println (i) continue LABEL}} |