Skip to main content
3 of 4
proper discussion of individual tags; removing remarks about [for]
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.

Given this meaning of , it would be appropriate to get rid of any variants of the tag that only differ by syntax or choice of language by synonimising (i.e. option #1 -- and not option #2, which would just give us yet another syntactic tag). Let's consider the tags mentioned here one by one:

  • should become a synonym.

  • should not become a synonym, as JavaScript for..in loops are unlike the typical foreach loops we are discussing here. It is a tricky tag to handle, as there are quite a few languages which, unlike JavaScript use for...in as their typical foreach. We would need to decide whether to retag in such cases, which seem to constitute about a third of the tag, as the "Related Tags" counts in the sidebar suggest. Fortunately, it is a relatively small tag, with 391 questions as of now.

  • , on the other hand, should become a synonym, as it is about the JavaScript spelling of the typical foreach. It is a very small tag, with only 28 questions as of now.

P.S.: For the sake of convenience, here is a SEDE query for quickly viewing related tag counts (i.e. given a tag, how many questions also have another tag). It can be useful to evaluate how usage of the tags being discussed here is spread across language tags.

duplode
  • 34.3k
  • 9
  • 64
  • 108