From 8ad16a96019e0dabfca8daf159b1af916a2a3797 Mon Sep 17 00:00:00 2001 From: eiffel-org Date: Mon, 30 Apr 2018 13:17:26 +0000 Subject: [PATCH] Update wikipage Iterating on a LIST. (Signed-off-by:tioui). git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@2011 abb3cda0-5349-4a8f-a601-0c33ac3a8c38 --- .../Mini-HowTo/Iterating-on-a-LIST.wiki | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 documentation/18.01/eiffel/Tutorials/Mini-HowTo/Iterating-on-a-LIST.wiki 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