row

Prev Next

Function Names

row

Description

This function returns the current row number as provided in the table context for partial table specifications. It is useful to access neighboring row numbers in the same table, for example row()-1 for the row above the current row.

In case nested (i.e. multiple overlaying) table contexts are available, then the the number of levels up can be specified in the function parameter to obtain the row number of one of the outer table contexts.

Attention: This function will assert an exception (error message) if the table context is not available or the depth value is too high.

Call as: function

Restrictions

Indirect parameter passing is disabled
table context for partial table specifications is required

Parameter count

0-1

Parameters

No.TypeDescription
1
input
numeral Depth

Specifies the depth in case nested partial table specifications is activated. 0 refers to the current table, 1 and bigger values to superior tables. 0 is assumed if no parameter is specified.

Default value: 0 (innermost table context)

Return value

TypeDescription
numeral Row number

Examples

  table initialize ( table 1,
  { { Animal, leg count }, { Worm,  0}, { Bird, 2 }, { Dog, 4 }, { Fly, 6 }, { Tick, 8 } } );

  table initialize ( table 2, { Color, Red, Blue, Green } );

  table process( table 1, echo("Row number: ", row(), " ", [Animal], " has ", [leg count], " legs." ) );

  with table( table 1, 2 )
  {
      table process( table 2,
      echo ("Row # in table 1: ", row(1), " (", [^Animal], ") and table 2: ", row(0), " (", [Color], ")" ) );
      // Note the accent circumflex in [^Animal]: This symbol refers to next upper context, like row(1).
  }

Output

Row number: 1 Worm has 0 legs.
Row number: 2 Bird has 2 legs.
Row number: 3 Dog has 4 legs.
Row number: 4 Fly has 6 legs.
Row number: 5 Tick has 8 legs.
Row # in table 1: 2 (Bird) and table 2: 1 (Red)
Row # in table 1: 2 (Bird) and table 2: 2 (Blue)
Row # in table 1: 2 (Bird) and table 2: 3 (Green)
Try it yourself: Open LIB_Function_row.b4p in B4P_Examples.zip. Decompress before use.

See also

col
with table
partial table specifications