Slice append function in Go

Append an element to the slice: 1 2 nums := []int{1, 2, 3} nums = append(nums, 4) Append multiple elements to the slice: 1 2 nums := []int{1, 2} nums = append(nums, 3, 4) Append slice to another slice:

Keyed array elements in Go

Unkeyed array elements: 1 2 3 4 5 6 7 example := [3]float64{ 1.3, 6.7, 4.0, } Keyed array elements: 1 2 3 4 5 6 7 example := [3]float64{ 0: 1.3, 1: 6.7, 2: 4.0, } Keyed array in different order:

break and continue labels

break and continue statements can be use with label in Go, similar to goto statement. It is optional. Scope of labels are limited to the function and does not conflict with variable name, as it live in separate space. break and continue with label is only used in for, switch and select statements.

Go Switch fallthrough

Switch cases in go can use fallthrough keyword to fall into next case without checking it’s condition if the current case has fallthrough statement at the end. For example: 1 2 3 4 5 6 7 8 9 10 11 12 13 i := 142 switch { case i > 100: fmt.

iota constant in Go

Linearly increasing or decreasing constant values can be declared using “iota”. For example: 1 2 3 4 5 6 7 8 9 10 11 func main() { const ( monday = 0 tuesday = 1 wednesday = 2 thursday = 3 friday = 4 saturday = 5 sunday = 6 ) } This can be simplified as: