github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/blog/content/slices/prog060.go (about)

     1  // +build OMIT
     2  
     3  // Copyright 2013 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package main
     8  
     9  import (
    10  	"fmt"
    11  )
    12  
    13  func Extend(slice []int, element int) []int {
    14  	n := len(slice)
    15  	slice = slice[0 : n+1]
    16  	slice[n] = element
    17  	return slice
    18  }
    19  
    20  func main() {
    21  	var iBuffer [10]int
    22  	slice := iBuffer[0:0]
    23  	for i := 0; i < 20; i++ {
    24  		slice = Extend(slice, i)
    25  		fmt.Println(slice)
    26  	}
    27  }