All my postings are for beginners.
Below is the example code snippet using break statement in while loop.
Code Snippet:
-- USING BREAK STATEMENT IN WHILE
DECLARE @cnt INT
SET @cnt=10
WHILE @cnt>=1
BEGIN
PRINT @cnt
SET @cnt=@cnt-1
IF(@cnt=5)
BEGIN
PRINT 'Break statement executed when count value is 5'
PRINT 'So values are not printed after value 5'
BREAK;
END
END
GO
Hope this helps.
Anilkumar
No comments:
Post a Comment