-
Notifications
You must be signed in to change notification settings - Fork 22
Eberon FOR..IN
vladfolts edited this page Sep 4, 2015
·
2 revisions
FOR..IN loop statement is used to iteratate through arrays, STRINGs and MAPs. For arrays and strings all elements are iterated from the beginning to the end.
FOR [key,] value IN array DO
...
END;
key is an optional variable standing for array/string's index (from 0 to LEN(array) - 1) or MAP's key. key type is INTEGER for arrays and strings and STRING for MAPs. value is a variable standing for element's value. These variables have no a separate declaration and their visibility scope is inside loop only. Also these variables are read-only - similar to non-VAR parameters.
VAR
a: ARRAY 3 OF BOOLEAN;
BEGIN
FOR i, v IN a DO
ASSERT(a[i] = v);
END;
(* not using key here *)
FOR v IN a DO
END;
END;
VAR
m: MAP OF INTEGER;
BEGIN
FOR k, v IN m DO
ASSERT(v = 0);
ASSERT(k # "");
END;
END;