This is a creation in Article, where the information may have evolved or changed.
Control structure:
Go control structure mainly has if,switch,for three kinds, and does not have while, can use for to replace while
If
The IF condition of go is not enclosed in parentheses, but the program body part must be enclosed in curly braces to solve the ambiguity in C language.
Switch
The branch ends even if there is no break
Any value can be used in the case
Branch conditional expressions can be omitted
For
The expression is not enclosed, it is more than the C language single expression example: for condition {} is used instead of while
+ +: In the Go language, + + is not an expression but is treated as a statement.
Type declaration:
In the go language, the declaration must begin with a reserved word, and the tangent type is after the variable name
Cases:
Type T struct {x, y int}//new type const N = 1024//constant var t1 T = new (t) T2 =:new (t) var t3 *t =&t2func f (i int) float {}func F2 (i int) (Flota,int) {}
: = Simple copy, indicating that the left variable is declared as the right type at the time of assignment
Generic type:
Go does not have the concept of a template, but the built-in Array,slce,map,channel, you can specify other types,
A slice (slice) is a type that is unique to go, and can be seen roughly as a pointer to an array
The map is similar to HashMap
Channel for concurrent programming, similar to pipeline
var a[5] string//array var s[] string//String slice var m map [int] string//mapvar c chan int//pipe F: = Stacj.get. (float)//cast