Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it "iterate through" or "iterate over" something? [closed]

"through" and "over" are useless adverbs.

Examples:

  • While iterating this collection, my code throws an error.

  • This code iterates the collection.

  • Your assignment is to write code that iterates the collection.

It's like saying "up north" or "down south". "up" and "down" are useless. Instead you should say, "I am going north for the summer." or "In the south, they grow cotton."


Not right or wrong, just some stats:

= term =           = Google =   = Github =
"iterate over"      1,440,000   10,569,846 search results
"iterate through"     908,000    5,605,973
"iterate thru"         44,200      141,982
——————————————————————————————————————————
"iterate on"          402,000      187,576
"iterate in"           63,300      117,962
"iterate across"       10,900      208,342
"iterate within"        8,470       14,577
"iterate along"         8,060        6,396
"iterate among"         5,970        2,960
"iterate against"       2,580        3,255
"iterate inside"        2,450       35,060
"iterate amongst"         406       22,274
"iterate amidst"           66            0

Google stats updated on 4/25/2018. Subsequent searches show that results are unstable.
Github stats updated on 4/25/2018. Only code occurrences are counted.


I think it depends on the object of the preposition; you iterate over the iterator, over the collection, over the container, over the list, over the range, etc. but you iterate through (the contents of) the list, through (the elements of) the container, through the (elements of ) the range, through (the elements of) the collection, etc. In almost all cases they are interchangeable; the only place I would use "over" but not "through" is with respect to the iterator, itself; but for any iterable object, I'd use either "over" or "through".


I would say iterate over, and this is the way I've always seen it written.


Both essentially mean the same!

So, you are free to choose whichever suits you.


I would always say "iterate over" because it emphasizes the (relatively important) fact that the iterators themselves are not contained in the container that is the subject of the iteration.

To say "iterate through", to me, would imply that one were looking at each element of the container in turn, which is not really what is happening.

In contrast, saying "iterate over" implies to me that one is receiving an external handle to each element of the container in turn, which is really what is happening.

However, there's nothing wrong with "iterate through", and anyone who understands iterators would surely understand both phrases.


Technically it's probably just "iterate" period. But its obvious what you mean in either case.