Skip to main content
1 of 4
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, for the reason pointed out by Machavity.

duplode
  • 34.3k
  • 9
  • 64
  • 108