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
BREAKstatement. The loop may be restarted by using the
- 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, the
ENDkeywords must be used.
-- Prints the numbers 1 to 10 in increasing order.
DECLARE @counter = 1;
WHILE @counter <= 10 BEGIN
SET @counter = @counter + 1;