Associative array/Iteration: Difference between revisions

no edit summary
No edit summary
Line 1,722:
</pre>
''Note:'' the order in which <code>pairs</code> iterates over non-integer keys is not defined, so the order of lines in the output of the above code may differ from one run to another.
 
=={{header|M2000 Interpreter}}==
<lang M2000 Interpreter>
Module checkit {
\\ Inventories are objects with keys and values, or keys (used as read only values)
\\ They use hash function.
\\ Function TwoKeys return Inventory object (as a pointer to object)
Function TwoKeys {
Inventory Alfa="key1":=100, "key2":=200
=Alfa
}
M=TwoKeys()
Print Type$(M)="Inventory"
\\ Norma Use:
\\ Inventories Keys are case sensitive
\\ M2000 identifiers are not case sensitive
Print M("key1"), m("key2")
\\ Iteration
N=Each(M)
While N {
Print Eval(N) ' prints 100, 200 as number
Print M(N^!) ' The same using index N^
}
N=Each(M)
While N {
Print Eval$(N) ' prints 100, 200 as strings
Print M$(N^!) ' The same using index N^
}
N=Each(M)
While N {
Print Eval$(N, N^) ' Prints Keys
}
\\ double iteration
Append M, "key3":=500
N=Each(M, 1, -1) ' start to end
N1=Each(M, -1, 1) ' end to start
While N {
While N1 {
Print format$("{0}*{1}={2}", Eval(N1), Eval(N), Eval(N1)*Eval(N))
}
}
}
Checkit
</lang>
 
 
=={{header|M4}}==
Anonymous user