Examples of JadeIterableIF Iteration

The following example uses the most‑basic form of a JadeIterableIF‑based foreach instruction with no options or as clause. The method in this example would accept any parameter that implements the JadeIterableIF interface, including any existing Collection object.

displayValues(iterable: JadeIterableIF);
vars
    any: Any;
begin
    foreach any in iterable do
        write any.display();
    endforeach;
end;

The following example uses a JadeReverseIterableIF‑based foreach instruction, iterating in reversed order using the JadeReversibleIteratorIF interface back method.

displayValuesReversed(iterable: JadeReverseIterableIF);
vars
    any: Any;
begin
    foreach any in iterable reversed do
        write any.display();
    endforeach;
end;

The following example uses a JadeIteratorIF‑based foreach instruction in conjunction with an as clause to provide a more‑specific operation. The method in this example would accept any parameter that is a Collection object of type Employee (or a subclass of Employee) or any JadeIterableIF implementor whose corresponding JadeIteratorIF implementation retrieves Employee instances.

writeEmployees(employees: JadeIterableIF);
vars
    employee: Employee;
begin
    foreach employee in employees as Employee do
        write employee.name & ", " & employee.calculateAge.String & " years old.";
    endforeach;
end;

The following example uses an implementor of the JadeIterableIF interface as the iterable‑expression on the foreach instruction. In this example, the FarmYard class implements JadeIterableIF but is not a subclass of the Collection class.

writeFarmStock(farmYard: FarmYard);
vars
    animal: Animal;
begin
    foreach animal in farmYard as Animal do
        write animal.display();
    endforeach;
end;

2020.0.01 and higher