Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
Niidae Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Sather
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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!
== Example of iterators == This program prints numbers from 1 to 10. <syntaxhighlight lang="eiffel" line> class MAIN is main is loop i := 1.upto!(10); #OUT + i + "\n"; end; end; end; </syntaxhighlight> The <code>loop</code> ... <code>end</code> construct is the preferred means of defining loops, although <code>while</code> and <code>repeat</code>-<code>until</code> are also available. Within the construct, one or more iterators may be used. Iterator names always end with an exclamation mark. (This convention is enforced by the compiler.) <code>upto!</code> is a method of the <code>INT</code> class accepting one <code>once</code> argument, meaning its value won't change as the iterator yields. <code>upto!</code> could be implemented in the <code>INT</code> class with code similar to the following one. <syntaxhighlight lang="eiffel"> upto!(once m:INT):SAME is i: INT := self; -- initialise i to the value of self, -- that is the integer of which this method is called loop if i>m then quit; -- leave the loop when i goes beyond m end; yield i; -- else use i as return value and stay in the loop i := i + 1; -- and increment end; end; </syntaxhighlight> Type information for variables is denoted by the postfix syntax <code>variable:CLASS</code>. The type can often be inferred and thus the typing information is optional, as in <code>anInteger::=1</code>. <code>SAME</code> is a pseudo-class referring to the current class.
Summary:
Please note that all contributions to Niidae Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Encyclopedia:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
Sather
(section)
Add topic