Advertisement
cwchen

[Go] Creating a slice dynamically.

Sep 20th, 2017
934
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.20 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5. )
  6.  
  7. func main() {
  8.     slice := make([]int, 5)
  9.  
  10.     for i := 0; i < len(slice); i++ {
  11.         n := i + 1
  12.         slice[i] = n * n
  13.     }
  14.  
  15.     for _, e := range slice {
  16.         fmt.Println(e)
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement