While loop Break and Continue statements-in sql server

While loop ,Break and Continue statements in sql server

Synatx of While loop
--------------------

   While

   Begins

    -stmts

   [Break | Continue]

   End


Every loop requires three things in common
------------------------------------------

 1) Initialization

    Which sets the starting point of a loop.

 2) Condition

    Which decides the ending point of the loops

 3) Iteration

    Which takes to the next level of the cycle either in forward or backword direction

  Example:
   Declare @x int =1

     While @x<=10

     Begin

       print @x

       set @x+=1

     End


Break inside while loop
-----------------------

    Whenever we use a break statement inside a loop the control directly jumps out of the loop

 Example:

  Declare @x int=0;

     While @x
     Begin

       set @x+=1;

       if @x=5
         break
        print @x

      End

      print 'End of the loop'
 

Continue under a while loop
---------------------------

   If we use continue under a wwhile loop the statements next to the continue statement wiil not be executed the control from there directly jumps to the iteration    part of the loop

    Example:        

Declare @x int=0;

       While @x
       Begin

         set @x+=1;

        if @x=5
          continue
         print @x

        End

        print 'End of the loop'


About Author: author 4 + years of Information Technology experience in understanding and analyzing the software and hardware engineering requirements, onsite and offshore management of product development. Expert work on design and development for windows,web,mobile Expert knowledge of C#,ADO.NET, ASP.Net MVC, ENTITY FRAMEWORK, LINQ,COLLECTIONS, JAVASCRIPT,AngularJs 1.0,Angular2, Jquery,Jquery-Ajax, SQL SERVER, XAML,Windows phone 8.1 Good knowledge of WCF-Restful services,WCF, WEB API-Services ,Web- Services,MIcrosoft-Azure,JUICE UI,HTML,CSS,AJAX Read More...

Join him on Google+ | Facebook | Linkedin

No comments