diff --git a/documentation/18.01/eiffel/Tutorials/Mini-HowTo/Iterating-on-a-LIST.wiki b/documentation/18.01/eiffel/Tutorials/Mini-HowTo/Iterating-on-a-LIST.wiki new file mode 100644 index 00000000..aa8e6bc2 --- /dev/null +++ b/documentation/18.01/eiffel/Tutorials/Mini-HowTo/Iterating-on-a-LIST.wiki @@ -0,0 +1,33 @@ +[[Property:uuid|96077603-DD2D-4D8C-A486-AF4BD066613A]] +[[Property:weight|0]] +[[Property:title|Iterating on a LIST]] +There is two Eiffel mecanisms 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]) + 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 language (like the for structure in Python for example). + +The other mecanism use the from until loop syntax. This syntax offer more possibilities that the across loop, but is more risky. + + + print_elements(a_list:LIST[INTEGER]) + do + from + a_list.start + until + a_list.exhausted + loop + print(a_list.item.out + "%N") + a_list.forth + end + end + \ No newline at end of file