foreach VEX function

The foreach statement lets you loop over every member of an array. The statement has two forms.

Simple form

foreach (value; array) statement;

This loops over the members of array. For each iteration, it copies the current member to value and then executes statement. For example:

int an_array[] = {1, 2}
int num;
foreach (num; an_array) {
    printf("%d", num);
}

VCC cannot handle inline declarations, such as foreach (int num; an_array).

Enumerated form

The second form lets you specify an enumeration variable:

foreach (index, value; array) statement;

For each iteration, this form assigns the current position in the array to index, copies the current member to value, and executes statement. For example:

string days[] = { "Mon", "Tue", "Wed", "Thu", "Fri" }
foreach (int i, string name; days) {
    printf("Day number %d is %s", i, name);
}

(This is similar to the common Python idiom for i, x in enumerate(xs):.)