loop

The loop filter takes a single filter body as argument:
  loop body

The loop filter evaluates body over and over, until body is false. The loop filter matches the position if the body was ever true, that is if body was evaluated more than once.

For example, this code counts the total number of positions in the game:

  cql (variations input foo.pgn)
  initial
  NumberPositions = 0
  loop {
    position NumberPositions
    NumberPositions += 1}
  comment ("Number of positions is: " NumberPositions)

This works because the position filter will match if its argument is less than the total number of positions. Thus, the body of the loop filter is evaluated k+1 times, where k is the total number of positions. On the last evaluation, when NumberPositions has value equal to the number of positions, the position filter will fail and the compound filter that is body will likewise fail, so the loop will exit.

The loop filter is rarely needed; it is only used in certain specialized situations.

Examples

The loop filter is used in parallelpaths.cql and serialpin.cql.