HOME/Articles/

Golang golang-foreach (snippet)

Article Outline

Go programming example 'golang-foreach'

golang-foreach

Golang beginners example: golang-foreach

package main

import (
    "fmt"
)

// declare variables and define array content
var strarray = []string{"lorem", "ipsum", "dolor", "sit", "amet"}

func main() {
    for index, data := range strarray {
        fmt.Println(index, data)
    }
}