Cold Help System: Programming: ColdC Reference Manual: Language Structure: Statements: Looping Statements: for-list


The for-list statement is used to traverse a list. It has the following syntax:

for iteration-variable in (what expr)
statement

iteration-variable must be a local variable (it cannot be an object variable), and what expr must be an expression resulting in a list or dictionary type. The interpreter executes statement once for each element in what, assigning the current element to the iteration-variable for the iteration. Here is an example of using a for-list statement on a list:

for s in (["foo", "bar", "baz"])
    .tell(s);

When executed, the method tell is called three times, the first time with an argument of "foo" (the first element in the list), the second time with "bar" (the second element in the list), and the third time with "baz" (the last element in the list).

When using a dictionary as what expr, the interpreter assigns each association in the dictionary to the iteration variable (see Dictionaries). For example, if the dictionary #[['count, 21], ['name, "foo"]] were to be used as the what expr, the first iteration would set iteration variable to ['count, 21], and the second iteration would set it to ['name, "foo"].

Assigning to the iteration variable within a for-list statement will not change the status of the loop; the interpreter remembers where it is at in what and will continue as normal.


for-list | for-range | while | break | continue


the Cold Dark