for all current table selected columns

Prev Next

Function Names

for all current table selected columns

Synopsis

for all table selected columns ( comparison expression, iterator column number, iterator value, iterator counter ) statement;
for all table selected columns ( comparison expression, iterator column number, iterator value, iterator counter ) {statements; }

Description

The loops works through selected columns (where comparisons do match) in the table and row number provided in the current context and executes the following statements specified.

Inside the loop, the iterator value (table cell read) and the index will be provided. The number of columns to process is determined by the 2nd function parameter (reference row number).

Call as: procedure

Restrictions

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

Parameter count

2-4

Parameters

No.TypeDescription
1
code
comparison expression
:string
comparison expression

This expression is applied to compare the column header names, regardless of row number specified in the 2nd parameter. The checking is done once before the loop starts. The loop behavior will not be affected if the header names are changed afterwards, for example renamed. Attention to inserting and deleting columns: The loop has memorized the actual column numbers (which will not change) and not the header names.

Attention: To avoid hijacking further function parameters as additional values to be compared, put the expression into parentheses if no operators, = or <> have been used. Not an issue if <, >, == or != operators are used.

Opt. 2
code
variable
:string
iterator column number

This value refers to the current column number

Opt. 3
code
variable
:string
iterator header name

This value refers to the current column header name

Opt. 4
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

  table initialize( animals,
      {{ Name, Class, Number of Legs,Surface},
       { Dog, Mammal, 4, Hair }, { Snake, Reptile, 0, Skin }, { Parrot, Bird, 2, Feathers }} );

  // Choose all columns with headers containing 's'. The list results for row 2.

  with table ( animals, 2 )
  {
      for all current table selected columns( ('*s*'), column[], header[], i[] )
      {
      echo( column[],": Column ", column[], " (", header[], ") = ", [column[]] );
      }
  }

  echo;

  // The simplified approach: [.] = current table, row and column. [.,0] = current table, column, and row 0

  with table ( animals, 2 )
  {
      for all current table selected columns('*s*')
      {
          echo( col(), ": Column (", [.,0], ") = ", [.] );
      }
  }

Output

1: Column 1 (Class) = Reptile
2: Column 2 (Number of Legs) = 0

1: Column (Class) = Reptile
2: Column (Number of Legs) = 0
Try it yourself: Open LIB_Function_for_all_current_table_selected_columns.b4p in B4P_Examples.zip. Decompress before use.

See also

for all table columns
for all current table columns
for all table selected columns