24 ms·
I still don't see how looping over a collection is different from looping over a sequence of numbers from 1 to n.
by kweingar 3y ago
I still don't see how looping over a collection is different from looping over a sequence of numbers from 1 to n.
- tester756 3y agoDepends what do you actually mean by sequence, but mostly purpose. Normal "for" is like: repeat this code body as long as condition is satisfied Foreach is more like: walk thru this collection Look (c#): foreach (var item in items) ... for (int i=0; i<10; i++) { } In the 2nd version it is possible to jumps ahead, back, do not move, etc. Generally play around "i's" values Meanwhile I haven't seen yet any1 trying to do anything like this in foreach, because it is meant for just walking thru collection