Thumb

Break and continue statement

9/14/2020 7:08:01 AM

Break and continue statement: The break and continue statement use to when specific condition is true then we can use the break statement for break the block and also, we use the continue statement for continue the code by condition. Now given bellow the code: 

DECLARE @COUNTER INT = 0
WHILE @COUNTER < 10 BEGIN
    SET @COUNTER = @COUNTER + 1
 
    IF @COUNTER = 7
        CONTINUE
 
    IF @COUNTER = 9
        BREAK
 
    PRINT @COUNTER
END

In this case we use the while loop then under the loop we use break and continue statement by the if condition.