Go Tutorial Part 6 For Loop
Contents
package main
import "fmt"
func main() {
cards := []string{"Ace of Diamond", newCard()}
cards = append(cards, "Six of Spades")
for i, card := range cards {
fmt.Println(i, card)
}
}
func newCard() string {
return "Five of Diamonds"
}
for: start defining a for loopindex: index of the element in the arraycard: current card we are iterating overrange cards: take the slice of card and range over
why := each time?
because each iteration throws the old variables away and mew are defined