Thursday 7 November 2013

USING CONTINUE STATEMENT IN WHILE-2

Hello,

Below is the example where Continue statement is used in While loop.

Code Snippet:

--USING CONTINUE STATEMENT IN WHILE
DECLARE @CNT INT
SET @CNT=11
WHILE @CNT>=1
BEGIN
--PRINT @CNT;
SET @CNT=@CNT-1;
IF @CNT=7
CONTINUE;
PRINT 'THE VALUE IS :'+CAST(@CNT AS VARCHAR(10));
END
GO

Description :
       
        When the count variable equals to 7 and IF condition will be successful and it executes the keyword continue and skips the print statement for value 7. "Continue" skips all the statements after that continue keyword and before the END. It will execute the next iteration.



Hopefully this helps.

Anilkumar



No comments:

Post a Comment