Go
Variables
Variables are defined as:
var name type = value
For example:
var x string = "Hello"
The type can be inferred if an initial value is given, e.g.
var x = "Hello"
or by using the :=
operator:
x := "Hello"
Constants can be defined by using the const
keyword instead of var
.
Loops
Go only supports the for
loop - unlike other languages it lacks while
, do while
etc. However, it is possible to emulate other loop constructs using for
.
Imports
Standard import notation:
import "fmt"
Multiple imports can be done either one line at a time or as a group:
import ( "fmt" "math" )
Names in packages are exported if they begin with a capital letter.