Advertisement
Koepnick

array/slice loops

Jan 15th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.23 KB | None | 0 0
  1. // range will enumerate an array or slice
  2. a := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
  3. for i, v := range a {
  4.     // Do stuff with i and v
  5. }
  6.  
  7. // Don't forget the _ can skip a variable assignment
  8. for _, v := range a{
  9.     // Do stuff with v
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement