Source file tour/moretypes/slices-of-slice.go

     1  //go:build OMIT
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"strings"
     8  )
     9  
    10  func main() {
    11  	// Create a tic-tac-toe board.
    12  	board := [][]string{
    13  		[]string{"_", "_", "_"},
    14  		[]string{"_", "_", "_"},
    15  		[]string{"_", "_", "_"},
    16  	}
    17  
    18  	// The players take turns.
    19  	board[0][0] = "X"
    20  	board[2][2] = "O"
    21  	board[1][2] = "X"
    22  	board[1][0] = "O"
    23  	board[0][2] = "X"
    24  
    25  	for i := 0; i < len(board); i++ {
    26  		fmt.Printf("%s\n", strings.Join(board[i], " "))
    27  	}
    28  }
    29  

View as plain text