for all

Prev Next

Function Names

for all, for all parameters

Synopsis

for all( set value, iterator value, iterator counter ) statement;
for all( set value, iterator value, iterator counter ) {statements; }

Description

The loop works through all elements in the set provided in the 1st function parameter. If the set is empty, then the loop will not be executed. This loop will not step into nested parameter elements.

This function name for all replaces the retired function name for all parameters even though this function name remains active for one more release.

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

2-3

Parameters

No.TypeDescription
1
input
set
string
parameters

Elements in this set will be provided. If a string is provided, then it will be converted to a set containing just one element.

2
code
variable
:string
iterator value

This variable is updated by this function in order to provide the value of the current parameter element. It is a copied value. Modifying this variable will not influence the loop

Opt. 3
code
variable
:string
iterator counter

This variable is updated by this function and provdes the index. It always begins with 0 and continues with 1, 2, etc.

Examples

               for all ( { He, Hi, Ho }, greetings[] ) print( "   Say: ",greetings[]);
               echo;
               for all ( 'He,Hi,Ho', greetings[] )     print( "   Say: ",greetings[]);
               echo;
               for all ( "He,Hi,Ho", greetings[] )     print( "   Say: ",greetings[]);
               echo;
               a[] = {A..C};
               for all ( a[], greetings[], i[] )     print( "   Say: ", i[], ":", greetings[]);

Output

   Say: He   Say: Hi   Say: Ho
   Say: He,Hi,Ho
   Say: He,Hi,Ho
   Say: 0:A   Say: 1:B   Say: 2:C
Try it yourself: Open LIB_Function_for_all.b4p in B4P_Examples.zip. Decompress before use.

See also

for all variables
for all characters

Notes

Manipulation while inside the loop:
1. The iterator cannot be manipulated. It will be overwritten at the next loop round.
2. If the iterator is deleted inside the loop, it will be reinstated at the next loop round. This applies to all loop variables.
3. If the target variable name is deleted, or its members are deleted / added, then the loop will end. If some of the members are removed, it will have an impact such as fewer loop cycles. Since the members are sorted in alphabetical order, the whole list of members may shift accordingly. Therefore I recommend not to manipulate this variable while inside the loop. Inside the loop: If the affected variable is deleted or a member variables removed, then the loop will do a premature end.