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
- condition: integer (0-1)
If this expression evaluates to 1, then the statements are executed. Otherwise, the loop is terminated. - statement: statement
The statements to execute if the condition is 1. If more than one statement is desired, theBEGIN
andEND
keywords must be used.
Example
-- Prints the numbers 1 to 10 in increasing order.
DECLARE @counter = 1;
WHILE @counter <= 10 BEGIN
PRINT @counter;
SET @counter = @counter + 1;
END