Use a traditional for loop to iterate:
nums := [5]int{1, 2, 3, 4, 5}
for i := 0; i < len(nums); i++ {
fmt.Printf("Index %d: %d\n", i, nums[i])
}
This gives you full control. You can skip elements, go backwards, or step by different amounts.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
Traditional loop
Use a traditional for loop to iterate:
nums := [5]int{1, 2, 3, 4, 5}
for i := 0; i < len(nums); i++ {
fmt.Printf("Index %d: %d\n", i, nums[i])
}
This gives you full control. You can skip elements, go backwards, or step by different amounts.