Aller au contenu principal

# forin

Loop in an arrray.

# FORIN

## NAME

forin - Allows to iterate around the array.

## SYNOPSIS

for i in expressions do … endfor;

## DESCRIPTION

This statement is used to loop through an expression. The expression must be an array or an associative array.

Note: In the followings examples, the _ between the { should be removed to make it work.

```res={_{for i in {} do " nb="; sn_nb; " i="; i.key; endfor}}. return res=.
res={_{for i in {x:1,y:2} do " nb="; sn_nb; " i="; i.key; endfor}}. return res= nb=0 i=x nb=1 i=y.
res={_{j={x:1,y:2}; for i in j do " nb="; sn_nb; " i="; i.key; endfor}}. return res= nb=0 i=x nb=1 i=y.
res={_{for i in {x:1,y:2} do " nb="; sn_nb; " i="; i.value; endfor}}. return res= nb=0 i=1 nb=1 i=2.
res={_{for i in {x:1,y:2} do " nb="; sn_nb; " i="; i.nbrows; endfor}}. return res= nb=0 i=2 nb=1 i=2.
res={_{for i in [1,2,4] do " nb="; sn_nb; " i="; i; endfor}}. return res= nb=0 i=1 nb=1 i=2 nb=2 i=4.
res={_{a=[]; for i in a do " nb="; sn_nb; " i="; i; endfor;}}. return res=.
res={_{a=[1,2,4]; for i in a do " nb="; sn_nb; " i="; i; i*=2; endfor a;}}. return res= nb=0 i=1 nb=1 i=2 nb=2 i=4[2,4,8].
```

In the case of an array, the variable get the value of each element of the array. If the user modifies the value, then the array is also modified.

In the case of an associative array the returned variable contains:

-key : key of the element

-value : value of the element

-nbrows : number of rows in the associative array.

In all other case, it returns a single element.