Thursday 7 November 2013

GOTO STATEMENT in WHILE LOOP-3

Hello,

In this post, I would like to post the While loop example with GOTO Statement.

Code Snippet :

--WHILE LOOP WITH GOTO STATEMENT
DECLARE @cnt INT
SET @cnt=11
WHILE @cnt>=1
BEGIN
SET @cnt=@cnt-1;
IF @cnt=7
GOTO break_out;
PRINT 'The value of count is :'+CAST(@CNT AS VARCHAR(10));
END
break_out:
GO

Description:

When GOTO statement executed, control will be moved where the GOTO "NAME" given in the code.
In the below example the name given to GOTO is "break_out"



Hope this helps.

Anilkumar

No comments:

Post a Comment