Go has an almost Python like function: Range.
Range is used to iterate over elements in a lot of different Go data structures.

Of course we can range over slices and arrays, like:

We get both the value and index when using the range function, though in the above example we didn’t use it.

--

--

In GO an array is a sequence of elements defined by a specific length. This is unlike other high-level programming languages like JavaScript, Python, and many more.

In GO arrays are always the same length, as they are defined. Here is an example of a initialization of an array of length 5 containing all zeroes, in GO:

We can then access or set new values for each of the “spots” in the array:

--

--

Go has several different value types, these are:

  • String
  • Integer
  • Float
  • Boolean
  • etc.

Here are some examples:

All these values can be assigned to a variable, and saved for later use. Go’s variables are explicitly declared, the type and value are then used by the compiler to e.g. check for the correctness of types when comparing two variables, or for function calls.

Here are some examples of variables, and the initialisation of variables:

--

--

Nikolaj Johannes Skole Jensen

Nikolaj Johannes Skole Jensen

Fullstack developer living in Denmark. Experience with both Web- and App development.