BREAK (TSQL Statement)

Execution jumps out of the WHILE loop.

The execution resumes at the next statement following the loop.

Syntax

BREAK

Remarks

In nested loops, BREAK exits only from the loop in which it occurs (innermost loop).

Example

DECLARE @i INT = 0;

WHILE @i < 1000
  BEGIN
  PRINT @i;
  IF @i = 4
    BREAK;

  SET @i += 1;
  END

PRINT 'End';

The result is:

0
1
2
3
4
End
RSQL, a simple alternative to Microsoft SQL Server