For Loops

For loops iterate once over the records in a window, or the data in a vector or dictionary. To iterate multiple times over the records, use a window iterator. They ensure that the data is consistent while they are in use.

To loop over every record in an input window called "input_window":
for (record in input_window) {
  ...
}
          
The variable record is a new variable; you can use any name here. The scope is the statement or block of statements in the loop; it has no meaning outside the loop. You can also set equality criteria in searching for records with certain values of fields. For example:
for (record in input_window where c=10, d=11) {
  ...
}
          
This statement has the same looping behavior, except limited to the records whose c field is 10 and d field is 11. If you search on the key fields, the loop runs at most one time, but it will run extremely fast because it will use the underlying index of the stream.
To loop over the values in a vector "vec1"where val is any new variable:
for (val in vec1) {
 ...
}
          
The loop stops when the end of the vector is reached, or the value of the vector is null.
To loop over the values in a dictionary "dict1" where key is any new variable:
for (key in dict1) {
 ...
}
          
It is common, inside the loop, to use the expression dict1[key] to get the value held in the dictionary for that particular key.