FOREACH |
Top Previous Next |
Use for looping an array.
Syntax <foreach_loop> ::= FOREACH (array_var AS var1 [KEY | INDEX var2] [SKIP NULLS]) DO <compound_statement>
<compound_statement> ::= {<block> | <statement>}
The FOREACH statement is used for executing a loop for each element in the given array array_var. The current element of the array is put into variable var1, optionally var2 can contain the index for the element. You can also optionally skip NULL-values for the loop.
The loop can be broken without evaluating the condition with a LEAVE statement or exited with a EXIT or RETURN statement. The next iteration can be forced using a CONTINUE statement.
Example EXECUTE UDSBLOCK() RETURNS(OUT_INT INTEGER) AS BEGIN /* create array with 5 elements, 1 NULL */ MyArray = Array.Create('this is text', NULL, 56.32, 'another string', 'val1');
FOREACH (MyArray AS arrayval KEY keyi) DO GUI.ShowMessage('Item ' || keyi || ' contains this value: ' || String.coalesce(arrayval, 'NULL'));
FOREACH (MyArray AS arrayval KEY keyi SKIP NULLS) DO GUI.ShowMessage('Item ' || keyi || ' contains this value: ' || String.coalesce(arrayval, 'NULL')); end |