Table of Contents

Variables and Types

Basic Types:

  • bool
  • string
  • int int8 int16 int32 int64
  • uint uint8 uint16 uint32 uint64 uintptr
  • byte // alias for uint8
  • rune
  • float32 float64 // alias for int32 represents a Unicode code point
  • complex64 complex128

Variable declaration:

var i int = 42

and shortcut version

i := 42

Loops

For loop, like java without the brackets. One can try it out here

for i := 0; i < 10; i++ {
   sum += i
}

the initialisation is optional:

sum := 1
for ; sum < 1000; {
   sum += sum
}

Functions

Go functions (func) are the “func” word follwed by parameters and return type

// a simple Go function 
func moles(mass amu) float64 { 
    return float64(mass) / grams 
} 
 
go_language_basics.txt · Last modified: 2018/08/21 06:31 by root
 
RSS - 200 © CrosswireDigitialMedia Ltd