3 ms·
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
by infogulch 11y ago
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.
- laumars 11y agoOoops, just seen this comment. Yes, you're right, your slice techniques do make a lot more sense than my examples.