Loops/Foreach: Difference between revisions

no edit summary
m (Everything in this web page's list of related tasks except "Loops/Foreach" can now be clicked on to take you to their respective web pages on rosettacode.org.)
No edit summary
Line 1,380:
</pre>
Note that <code>ipairs()</code> ignores non-numeric and non-positive integer keys.
 
=={{header|M2000 Interpreter}}==
Iterators we have for Arrays, Inventories and Stacks (containers). Each(object Start to End), or Each(object 1 to -1) or Each(Object, 1,-1). We can use -2 for second from end item. We can use step inside while iterator {} using Iterator=Each(object, new_start, end_item). We can read cursor using ^. So Print k^, k2^, k1^ return positions (from 0 for inventories). We can use more than one iterators for an object.
 
<lang M2000 Interpreter>
Module Checkit {
\\ Inventories may have keys or keys/values
\\ here keys are values too
Inventory Alfa="Apple", "Banana", "Coconut"
\\ key 30 has value 25, other keys have value same as key.
Inventory Beta=100, 30:=25, 20, 5
Print "Parallel"
k=Each(Alfa)
k1=Each(Alfa End to Start)
k2=Each(Beta)
\\ Parallel iterators
\\ when one of them end then while end too.
\\ so 5 not printed. Print 100, 25, 20
While k,k2, k1 {
Print Eval$(k), Eval$(k1), Eval(k2)
}
Print "Nested"
\\ Nested iterators
k=Each(Alfa)
While k {
k1=Each(Alfa End to Start)
While k1 {
Print Eval$(k), Eval$(k1)
}
}
}
Checkit
</lang>
 
=={{header|Maple}}==
Anonymous user