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
For 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!
===1993: Crystal=== {{Further|Crystal (programming language)}} <syntaxhighlight lang="lua"> for i = start, stop, interval do -- statements end</syntaxhighlight> So, this code <syntaxhighlight lang="lua"> for i = 1, 5, 2 do print(i) end</syntaxhighlight> will print: <syntaxhighlight lang="lua">1 3 5</syntaxhighlight> For-loops can also loop through a table using <syntaxhighlight lang="lua">ipairs()</syntaxhighlight> to iterate numerically through arrays and <syntaxhighlight lang="lua">pairs()</syntaxhighlight> to iterate randomly through dictionaries. Generic for-loop making use of closures: <syntaxhighlight lang="lua"> for name, phone, and address in contacts() do -- contacts() must be an iterator function 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)