Is it "iterate through" or "iterate over" something?

TerminologyIteration

Terminology Problem Overview


Just thought about it. Is there a semantic distinction, or are we free to choose?

EDIT I accepted @roygbivs answer, because most of the answers suggested that it is a matter of taste which one to choose, and that it doesn't really change the meaning. In that case, since the through and the over don't carry any information at all (in that particular context), they can be left out.

Terminology Solutions


Solution 1 - Terminology

"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."

Solution 2 - Terminology

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.

Solution 3 - Terminology

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".

Solution 4 - Terminology

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

Solution 5 - Terminology

Both essentially mean the same!

So, you are free to choose whichever suits you.

Solution 6 - Terminology

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.

Solution 7 - Terminology

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

Solution 8 - Terminology

I use "loop over". Simple.

Solution 9 - Terminology

The summary text for System.Collections.Generic.IEnumerator GetEnumerator() says:

> Returns an enumerator that > iterates through the collection.

Personally I say through ... but really I don't think it matters which one you use.

Solution 10 - Terminology

The important word is iterate, what filler you place with it really doesn't matter.

Solution 11 - Terminology

I picture "iterating through" something, the way I do a file cabinet. Maybe it's just personal preference though, given my mental image - I think "Iterate Over" is the more common usage.

Solution 12 - Terminology

I use both at random, sometimes in the same sentence. Dropping the connecting word is bad grammar and neither is meaningful.

Solution 13 - Terminology

Dictionary says "iterate" is a transitive verb meaning to "say or do again; repeat".

Would you "repeat over" something you just said, or "repeat through" it? I think you'd just plain repeat it. Or just plain iterate it, as you prefer.

Having said that, if you're using "iterate" as some kind of synonym for "loop"... looping through data one iteration at a time, perhaps, then maybe you ARE "iterating through". This is a minefield!

Solution 14 - Terminology

I think they are interchangeable for most practical purposes, but in my comments I personally tend to use them with a small distinction: I interpret to "iterate over" something to be similar to the sense that you would say "I'll look over it". That is, it's not a deep inspection: you are browsing over it looking for something. Conversely, to "iterate through" is to go through each and every one purposefully.

So if I was just searching for one item in a list I would say I was "iterating over" the list.....if I was applying some transformation to each item, it would be "iterate through".

Solution 15 - Terminology

Either is a rhetoical tautology. You should remove the superfluous preposition. As in

> "This loop iterates the top 10 products"

or, perhaps

> "I am iterating the answers looking for the one to accept"

Solution 16 - Terminology

Common Lisp's LOOP macro uses for element in list, but for element across array (it's different so the compiler can generate more efficient code ... yeah, it's weird), suggesting that the preposition isn't really that important.

Solution 17 - Terminology

There is a better way.

J's members are dissimilar, but all can be incremented.
Having incremented every member of 'J' ...
J contains incrementable elements.
J refers to several items.
J refrances several items.
Everything in J is incrementable.
Everything J refers to should necessarily be thought of as being storable in a set.
Sequentially referring to J's contents ...
Apply between each element of J and R until all possible compatible pairs have been found.
Ask J using it's 'ask' function to sequentially apply addition between it's contents and return the result.

It's like the word "has", that can so often reduce a whole sentance to a single word.

Why not keep iterate for iteration, like this -> circle, triangle, octagon, pentagon, hexagon.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBjörn PollexView Question on Stackoverflow
Solution 1 - Terminologyuser113476View Answer on Stackoverflow
Solution 2 - TerminologykennytmView Answer on Stackoverflow
Solution 3 - TerminologyMichael Aaron SafyanView Answer on Stackoverflow
Solution 4 - TerminologyCocowallaView Answer on Stackoverflow
Solution 5 - TerminologyMahesh VelagaView Answer on Stackoverflow
Solution 6 - TerminologyTyler McHenryView Answer on Stackoverflow
Solution 7 - TerminologyJoshView Answer on Stackoverflow
Solution 8 - TerminologyAMissicoView Answer on Stackoverflow
Solution 9 - TerminologyPeanutView Answer on Stackoverflow
Solution 10 - TerminologyAmberView Answer on Stackoverflow
Solution 11 - TerminologySqlRyanView Answer on Stackoverflow
Solution 12 - TerminologyJoshuaView Answer on Stackoverflow
Solution 13 - TerminologythesunneversetsView Answer on Stackoverflow
Solution 14 - TerminologyMisterMisterView Answer on Stackoverflow
Solution 15 - Terminologyserg10View Answer on Stackoverflow
Solution 16 - TerminologyKenView Answer on Stackoverflow
Solution 17 - Terminologyalan2hereView Answer on Stackoverflow