Share via


ITERATE statement

Applies to: check marked yes Databricks Runtime 16.3 and later

Important

This feature is in Public Preview.

Terminates the execution of an iteration of a looping statement and continues with the next iteration if the looping condition is met.

This statement may only be used within a compound statement.

Syntax

ITERATE label

Parameters

  • label

    The label identifies a looping statement that contains the ITERATE statement directly or indirectly.

Examples

-- sum up all odd numbers from 1 through 10
> BEGIN
    DECLARE sum INT DEFAULT 0;
    DECLARE num INT DEFAULT 0;
    sumNumbers: LOOP
      SET num = num + 1;
      IF num > 10 THEN
        LEAVE sumNumbers;
      END IF;
      IF num % 2 = 0 THEN
        ITERATE sumNumbers;
      END IF;
      SET sum = sum + num;
    END LOOP sumNumbers;
    VALUES (sum);
  END;
25