for all table selected rows

Prev Next

Function Names

for all table selected rows

Synopsis

for all table selected rows ( table name, reference column, iterator value, iterator counter ) statement;
for all table selected rows ( table name, reference column, iterator value, iterator counter ) {statements; }

Description

This loop works through all selected rows (except the header row) in the table and executes the subsequent statements accordingly.

The selection is done with the expression provided in the 2nd function parameter. This expression is executed for every row in order to decide whether to run the following statements inside the loop or not.

.

Call as: procedure

Restrictions

Indirect parameter passing is disabled
This function provides a table context for partial table specifications with table name and row number

Parameter count

2-5

Parameters

No.TypeDescription
1.
input
string Table Name

Name of exsting table

2.
code
expression
:string
Expression to select rows

Specify the conditions or rules to selecte the rows. See expressions to select rows.
The table context for partial table specifications is available for referencing just the columns easily. Example: [Year]>=2022.
Attention: Comparison operators = and <> (instead of == and !=) may hijack the next function parameters for its own use as additional comparison operands, e.g. a[]=1,3,5. As long this comparison is not made in the last function parameter, then put parentheses around them, e.g. ... , (a[]=1,3,5), ....

Opt. 3.
input
table columns Reference Column

Specify 1 column header name or 1 column number. This column will be used to count the rows in the table and return the iterator value from every row. If partial table references are used, the point (e.g. [.]) will refer to this specified column.

Opt. 4
code
variable
:string
iterator value

This variable is updated by this function in order to provide the current value taken from the specified table column and referenced row. The variable is always of type 'quoted string', even if containing numbers or dates. You need to convert the type by hand if needed.

Opt. 5
code
variable
:string
iterator counter

Equivalent to current row number while working throuh the table. This variable is updated by this function and provdes the index. It always begins with 0 and continues with 1, 2, etc.

Examples

               table initialize ( colors, { { EN, FR }, { red, rouge }, { blue, blue }, { green, vert }, { rose, rosé }, { yellow, jaune } } );

               // Simple case with 2 parameters:
               for all table selected rows( colors, [EN]='r*')
               {
                       echo( [EN], " -> ", [FR] ); // All French colors ending with 'e'
               }

               // All 5 parameters in use:
               // Note the extra parentheses for 2nd parameter to avoid hijacking further function parameters into the comparison
               for all table selected rows( colors, ([FR]='*e'), EN, value[], index[] )
               //
               {
                       echo( "index ", index[], ": ",value[], " -> ", [FR] ); // All French colors ending with 'e'
               }

Output

red -> rouge
rose -> rosé
index 1: red -> rouge
index 2: blue -> blue
index 5: yellow -> jaune
Try it yourself: Open LIB_Function_for_all_table_selected_rows.b4p in B4P_Examples.zip. Decompress before use.

See also

table process selected rows
for all table selected columns