The following example of a range of
vars count : Integer; begin foreach count in 1 to 10 do write count; // Outputs 1 2 3 4 5 6 7 8 9 10 endforeach; end;
Use the reversed option to indicate that the range of numbers is to be assigned to the variable in reverse order. The following example displays the integers in the range 1 through 10 in descending order.
vars count : Integer; begin foreach count in 1 to 10 reversed do write count; // Outputs 10 9 8 7 6 5 4 3 2 1 endforeach; end;
The following example displays only the even integers in the range 1 through 10 in descending order.
vars count : Integer; begin foreach count in 10 to 1 step -2 do write count; // Outputs 10 8 6 4 2 endforeach; end;
The following example, using the reversed option and the where clause, displays in descending order the integers in the range 1 through 10, except for 5.
vars count : Integer; begin foreach count in 1 to 10 reversed where count <> 5 do write count; // Outputs 10 9 8 7 6 4 3 2 1 endforeach; end;