Go Languages basic grammar
The last chapter we already know the basic structures of the Go language, in this chapter we will learn basic grammar Go language.
Go mark
Go program may be composed of a plurality of marks, it may be keywords, identifiers, constants, a string, a symbol. As the GO statement tag consists of six components:
fmt.Println("Hello, World!")
6 is a flag (one per line):
1. fmt
2. .
3. Println
4. (
5. "Hello, World!"
6. )
Line separator
In the Go program, a statement on behalf of his party ended. Each statement is not like the other C family of languages with a semicolon; at the end, because these jobs are done automatically by the compiler Go.
If you intend to write multiple statements on the same line, they must be used; artificial distinction, but in the actual development, we do not encourage this practice.
The following two statements:
fmt.Println("Hello, World!")
fmt.Println("CodingDictCodingDict教程:CodingDict.com")
Note
Comments are not compiled, each package should have a relevant comment.
Single-line comments are the most common form of comments, you can use single-line comments begin with // anywhere. Multi-line comments, also called block comments at the beginning have been to / *, and to *
end with a /. Such as:
// 单行注释
/*
Author by CodingDictCodingDict教程
我是多行注释
*/
Identifier
Identifier is used to named variables, like the type of program entities. An identifier is actually a letter or a plurality of (A ~ Z and a ~ z) numbers (0 to 9), _ underlined sequence consisting of, but the first character must be a letter huo underlined number is not.
The following are valid identifiers:
mahesh kumar abc move_name a_123
myname50 _temp j a23b9 retVal
The following are invalid identifiers:
- 1ab (start with a number)
- case (keyword Go language)
- a + b (the operator is not allowed)
Keyword
Here are the Go will use to 25 keywords or reserved words:
break | default | func | interface | select |
case | defer | go | map | struct |
chan | else | goto | package | switch |
const | fallthrough | if | range | type |
continue | for | import | return | where |
In addition to the above description of these keywords, Go language there are 36 predefined identifiers:
append | bool | byte | cap | close | complex | complex64 | complex128 | uint16 |
copy | false | float32 | float64 | imag | int | int8 | int16 | uint32 |
int32 | int64 | iota | only | make | new | nil | panic | uint64 |
println | real | recover | string | true | uint | uint8 | uintptr |
Program typically consists of the keyword, constants, variables, operators, type, and functions.
May be used to program these delimiters: parentheses (), brackets [] and braces {}.
The program may use these punctuation marks: ,,,;,: and ....
Go Language spaces
Go declaration of variables in the language must be separated by a space, such as:
var age int;
Statement to make appropriate use of the space program look easy to read.
No spaces:
fruit=apples+oranges;
Include spaces between variables and operators, the program looks more beautiful, such as:
fruit = apples + oranges;
This switched: http://codingdict.com/article/6748