Iterating on a LIST

There are two Eiffel mechanisms to iterate on every element of a LIST.

The first it the across loop. The across can be used on every ITERABLE object (including LIST objects).

print_elements(a_list:LIST[INTEGER]) -- Print every elements on `a_list' do across a_list as la_list loop print(la_list.item.out + "%N") end end

Note that the temporary variable (la_list in the example) represent an iterator of the ITERABLE object, and not directly an element like in many other languages (like the for structure in Python for example).

The other mechanism uses the from until loop syntax. This syntax offer more possibilities than the across loop, but is riskier.

print_elements(a_list:LIST[INTEGER]) -- Print every elements on `a_list' do from a_list.start until a_list.exhausted loop print(a_list.item.out + "%N") a_list.forth end end

cached: 07/19/2018 8:42:35.000 AM