Go Language Tutorials: Go Syntax
We have already discussed the structure of a Go programming language in the previous blog. So now it will be very easy to understand more about the language in-depth with all the syntax.
Go Tokens
All the programming languages have tokens which are consist of an identifier, string literals, a keyword or a symbol, and also a constant. For example, Let’s check the following code.
fmt.Println(“FooBar!”)
The above statement consists of the following tokens -
fmt
.
Println
(
“FooBar!”
)
Line separator in Go
In any typical programming language like C or Java, the line is separated using “;” (semicolon) which is not true in the case of the Go language. The Go compiler automatically places “;” (semicolon) at the end of the statement while compiling the program.
Comments in Go
In any programming language comments are used as a helping text in a program source code, they are also ignored by the compiler. There are 2 ways of declaring a comment: “//” or “/**/”.
You cannot declare comments inside comments.
Identifiers in Go
An identifier in Go language is a name used to identify functions, variables, and any other item which is user-defined. Identifiers usually start with a letter a to z or A to Z, or an _ (underscore) with more letters or digits or underscores.
For example, movie_name
Go does not allow special characters such as $, %, and @ along with identifiers. Go language is a case-sensitive programming language. Thus, Information and information are two different identifiers in Go.
Keywords in Go
In any programming language, Keywords are reserved words that are already defined in a language and cannot be used as a variable or a constant.
Break | default | func | interface | select |
case | defer | Go | map | Struct |
chan | else | Goto | package | Switch |
const | fallthrough | if | range | Type |
continue | for | import | return | Var |
0 Comments