Break Staement in Store Procedure

Break Staement:

 

When a Break statment execute inside a loop then break statment terminate loop and program run for next stament.Here we understand through Example.

 

Example:

 

DECLARE @LoopCount INT = 1
WHILE ( @LoopCount <= 3)
BEGIN
    PRINT @LoopCount 
    IF(@LoopCount = 3)
        BREAK
    SET @LoopCount  = @LoopCount  + 1
END
PRINT 'Statement after break'
 
 

Result:   1  

          2

           Stament after break

 

In above example first and second statment run ok when 3 rd statment encountered with break statment,then loop terminated and out from loop.