NextGen Knowledge Center

for each…in loops

These loops are part of the E4X standard. Unlike other for loop constructs, for each…in loops usually have no explicit counter; they essentially say "do this to everything in this set" rather than "do this X times." This avoids possible off-by-one errors and makes code easier to read. These loops are used to iterate through elements in an array (or collection) or in the property values of an object.

Syntax (for each...in loops)Example
for each (var in object) {
    // Code to execute
}
var sources = new Array ();
sources [0] = "Customer 1";
sources [1] = "Customer 2";
sources [2] = "Customer 3";
for each (src in sources) {
    logger.info(src);
}