foreach. Going through hash elements

^hash.foreach[key;value]{body}
^hash.foreach[key;value]{body}[delimiter]
^hash.foreach[key;value]{body}{delimiter}

The method works the same way as the method
menu of class table. It goes through all hash keys and relevant values (since version 3.4.0 the method goes through elements in order of putting the elements into the hash, before-order is not defined).

key-name of variable to return keys' names
value-name of variable to return keys' values
body-code to be executed for each key-value
delimiter-code to be executed before each non-empty non-first body

You can force finish the loop using break operator or finish current step and go to next one using continue operator. [3.2.2]

Example

Code…

$man[
   $.name[
Jack]
   $.age[
22]
   $.sex[
m]
]
^man.foreach[key;value]{
        $key
=$value
}[
<br />]

…will return…

name=Jack
age=22
sex=m



Copyright © 1997–2021 Art. Lebedev Studio | http://www.artlebedev.com Last updated: 27.01.2021