LoginSignup
1
0

More than 1 year has passed since last update.

Go 言語でスライスの要素をすべて展開して、インデックスの順序と値を出力する例 ( #go foreach slice all elements )

Last updated at Posted at 2020-03-16
// https://golang.org/pkg/math/rand/

package main

import (
	"fmt"
)

func main() {

	cards := []string{"2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"}
	for i, card := range cards {
		fmt.Println(i, card)
	}

}

// e.g
//
// 0 2
// 1 3
// 2 4
// 3 5
// 4 6
// 5 7
// 6 8
// 7 9
// 8 10
// 9 J
// 10 Q
// 11 K
// 12 A

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0