WHILE Statement

Repeatedly executes the provided statements as long as the condition expression evaluates to the integer 1.

The loop may be ended without regard to the condition expression by using the BREAK statement. The loop may be restarted by using the CONTINUE statement.

Syntax


Parameters

Example

-- Prints the numbers 1 to 10 in increasing order.
DECLARE @counter = 1;
WHILE @counter <= 10 BEGIN
PRINT @counter;
SET @counter = @counter + 1;
END