Skip to main content
2 of 4
added 115 characters in body
duplode
  • 34.3k
  • 9
  • 64
  • 108

Like Michael Kohl, I believe purely syntactic tags are by and large superfluous. In the case of , though, there is a bit more than mere syntax involved, to the extent it is relevant to discuss iteration over a data structure as a separate subconcept of iteration in general. The tag wiki, language agnostic as it is, fits that interpretation:

foreach is a looping construct that executes a given piece of code for each element in a list/collection/array. In contrast to a for loop, the foreach loop doesn't require the coder to maintain a counter variable to avoid off-by-one (fencepost) bugs. [...]

I believe that is enough to justify the existence of , though those of you with more experience in handling newbie questions in OO languages might be in a better position to judge.

As for the syntactic variants of , I feel it would be appropriate to get rid of them by synonimising (i.e. option #1 -- and not option #2, which would give us yet another syntactic tag). Note that should not be made a synonym, as it often refers to a different kind of loop (I agree with this specific point in Machavity's answer).

duplode
  • 34.3k
  • 9
  • 64
  • 108