Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Foreach loop
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Eiffel === The iteration (foreach) form of the [[Eiffel (programming language)|Eiffel]] loop construct is introduced by the keyword <code lang=Eiffel>across</code>. In this example, every element of the structure <code>my_list</code> is printed: <syntaxhighlight lang="Eiffel"> across my_list as ic loop print (ic.item) end </syntaxhighlight> The local entity <code>ic</code> is an instance of the library class <code>ITERATION_CURSOR</code>. The cursor's feature <code>item</code> provides access to each structure element. Descendants of class <code>ITERATION_CURSOR</code> can be created to handle specialized iteration algorithms. The types of objects that can be iterated across (<code>my_list</code> in the example) are based on classes that inherit from the library class <code>ITERABLE</code>. The iteration form of the Eiffel loop can also be used as a boolean expression when the keyword <code>loop</code> is replaced by either <code>all</code> (effecting [[universal quantification]]) or <code>some</code> (effecting [[existential quantification]]). This iteration is a boolean expression which is true if all items in <code>my_list</code> have counts greater than three: <syntaxhighlight lang="Eiffel"> across my_list as ic all ic.item.count > 3 end </syntaxhighlight> The following is true if at least one item has a count greater than three: <syntaxhighlight lang="Eiffel"> across my_list as ic some ic.item.count > 3 end </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)