Example of initializing an array of strings in Go

This Go example program illustrates how to initialize an array of strings.

package main

import (
        "fmt"
)

// Using var

var validTags = []string{
        "html",
        "body",
        "head",
}

func main() {

        // Using :=

        stringarray := []string{
                "fee",
                "fi",
                "fo",
                "fum",
        }
        for _, s := range (stringarray) {
                fmt.Println (s)
        }
}

(download)


Copyright © Ben Bullock 2009-2023. All rights reserved. For comments, questions, and corrections, please email Ben Bullock (benkasminbullock@gmail.com) or use the discussion group at Google Groups. / Privacy / Disclaimer