... >> Computer Science >> Programming >> For Each Loops
For Each Loops
Definition: For each (or foreach) is a computer language idiom for traversing items in a collection. Foreach is usually used in place of a standard for statement. Unlike other for loop constructs, however, foreach loops (usually) maintain no explicit counter: they essentially say "do this to everything in this set", rather than "do this x times". This can potentially avoid off-by-one errors and make code simpler to read. In object-oriented languages an iterator, even if implicit, is often used as the means of traversal.
Source: Reges & Stepp, 2007
Example: Example sentence for context: "Java 5 introduced a new loop construct that simplifies many certain array loops- it’s known as the enhanced foor loop, or the for-each loop."