Contents
Display Legacy Contents

 Print
    For Each...End For Each, For Each Loop  
For each is an action for traversing items in a collection. For each is usually used in place of a standard for statement Unlike other for loop constructs, however, for each loops usually maintain no explicit counter, they essentially say "do this to everything in this set", rather than "do this x times". This avoids potential off-by-one errors and makes code simpler to read.

This action have the following options: Browse a Table Control, Browse the result of a Stored Procedure, Browse a Result of a Select Statement, Browse a SQL Advanced, Browse the tokens of a String, Browse the Childs of a XML and For.

Parameters

Browse a Table Control: 
 
Table Control <unquoted string>
  The name of the table control that the user wants to browse.
   
Target <unquoted string> 
  The control or variable that saves the value of each for iteration. 
   
Browse the result of a Stored Procedure: 


The parameters of that option are the same of Exec. Procedure action. Please see here.
   
Browse a Result of a Select Statement:
 
  The parameters of that option are the same of Select action. Please see here. 
   
Browse a SQL Advanced: 
 
  The parameters of that option are the same of SQL Advanced action. Please see here.
   
Browse the tokens of a String:
 
Source String <string> 

This parameter is the string that the user wants to browse. 
   
String Separator <string> 
  This parameter is the string separator for the source string.
   
Target For Each Token <string>
  The control or variable to save each token.
   
Browse the Childs of a XML:

Source XML <string> 
  The complete path and name of the source XML file.
 
Child's Name <string> 
  The name of the XML child that the user wants to browse. 
 
Ignore Name´s Prefix <combobox> 
  This parameter indicates that if the user wants or not to ignore the prefix of each name. This parameter have thre possible values: Yes, No, dynamic.
 
Content's Target <string> or <numeric> 
  The control or variable that saves the result of each iteration. 
 
Attribute <string> 
  The name of the XML attribute.
 
Target <string> or <numeric> 
  The control or variable that saves the XML attribute.
 
(...)
 
Nth-Attribute <string>  
  The name of the nth-XML attribute. 
 
Nth-Target <string> or <numeric> 
  The nth-control or nth-variable that saves the nth-XML attribute.
   
For 

Type <string> or <numeric> 
  The type of the step and initial value of the for action.
 
Enumerator <string> or <numeric>  
  Object used to control the iteration.
 
Initial Value <string> or <numeric>  
  Expression used to initialize the enumerator. 
 
While <unquoted string> 
  Condition to continue the loop. 
   
Step <unquoted string>  
  Expression to set the value of Enumerator in each iteration. 

     
Consider the following information:



Figure 1 - An example of a table control of a database table. The name of this table control is TableExample.


Example 1

Example 2
Browse a Table Control:

For Each(Table Control; CTRL(TableExample); VAR(0))

End For Each



Result:

Iteration Variable Value
1 VAR(0) 1
2 VAR(0) 2
3 VAR(0) 3

Note that in each iteration, VAR(0) stores the value of line index of the table control (see Figure 1).

Browse the tokens of a String:

Set Value(VAR(0); String; "Kalipso is a tool to develop mobile applications.")

For Each(Token of String; VAR(0); " "; VAR(1))

End For Each

Result:


Iteration Variable Value
1 VAR(1) "kalipso"
2 VAR(1) "is"
3 VAR(1) "a"
4 VAR(1) "tool"
5 VAR(1) "to"
6 VAR(1) "develop"
7 VAR(1) "mobile"
8 VAR(1) "applications"

Example 3

Example 4
For:

Set Value(VAR(0); Numeric; 0)

For Each(FOR; Numeric; VAR(0); 1; VAR(0) <= 5; VAR(0) + 1)

Set Value(VAR(1); Numeric; VAR(1) + 1)

End For Each

Result:


Variable Value
VAR(0) 6
VAR(1) 5

For:

Set Value(VAR(0); String; "")

For Each(FOR; String; VAR(0); ""; Length(VAR(0)) < 10; VAR(0) + "a")

Set Value(VAR(1); Numeric; VAR(1) + 1)

End For Each

Result:

Variable Value
VAR(0) "aaaaaaaaaa"
VAR(1) 10

     
 

    See also
    Samples

     
     
    Updated: 3/21/2018 5:49 PM

     

    Iteration Variable Value
    1 VAR(0) 1
    2 VAR(0) 2
    3 VAR(0) 3
    Iteration Variable Value
    1 VAR(1) "kalipso"
    2 VAR(1)  "is" 
    3 VAR(1)   "a"
    4 VAR(1)  "tool"
     5  VAR(1)  "to"
    6 VAR(1)  "develop"
    7 VAR(1)  "mobile"
    8 VAR(1)  "applications"