Re:Experiences Using Go as a Teaching Language with Young Pr...
by infogulch on Thursday August 13, 2015 @11:36PM
(#10058507)
Slicing is free and can be done inline, so your first and third examples can be changed to the range syntax:
// iterate half the stack:
for i := range slice[:len(slice)/2] {}
// iterate from a different starting position:
for i := range slice[5:] {}
That still leaves stepping and reverse, but I've found those are relatively rare, especially compared to the other two.
for range does iterate over integer arrays / slices. The reason the C-style for loop exists is because sometimes you don't want to iterate the entire stack. eg