T-SQL Tutorial

CONTINUE


In SQL Server, the CONTINUE statement is used inside a WHILE statement and restarts the WHILE loop.


Syntax

WHILE Boolean_expression
{ sql_statements | transact_sql_statement | CONTINUE }


Example of CONTINUE inside WHILE

The following example uses the CONTINUE statement inside a WHILE loop. In the body of WHILE statement, the @count variable is incremented by 1 at each iteration. As long as @count is less than or equal to 5, the WHILE loop will continue to run.

USE model
GO
DECLARE @count int
SET @count = 1
WHILE @count < 10
BEGIN
PRINT 'Test'
SET @count = @count + 1
IF @count <= 5
CONTINUE;
ELSE
BREAK;
END;
GO