title: Break keyword vs Variable in WHILE loop
body: <p>We are using <code>WHILE</code> loop in SQL Server 2008 instead of Cursor. Now I want to find which method is best to write <code>WHILE</code> loop in my procedure.</p>
  
  <p><strong>Method 1 (Using BREAK Keyword):</strong> </p>
  
  <pre><code>DECLARE @V_Counter INT = 1;
  
  WHILE (1 = 1)
  BEGIN
      PRINT @V_Counter;
      SET @V_Counter = @V_Counter + 1;
  
      IF @V_Counter = 4
      BEGIN
          BREAK;
      END
  END
  </code></pre>
  
  <p><strong>Method 2 (Using BOOL VARIABLE):</strong> </p>
  
  <pre><code>DECLARE @V_Counter INT = 1, @V_CloseLoop TINYINT = 1;
  
  WHILE (@V_CloseLoop = 1)
  BEGIN
      PRINT @V_Counter;
      SET @V_Counter = @V_Counter + 1;
  
      IF @V_Counter = 4
      BEGIN
         SET @V_CloseLoop = 0;
      END
  END 
  </code></pre>
  
  <p><strong>My questions are:</strong> </p>
  
  <ul>
  <li>Which method I have to use or both are same? </li>
  <li>Is there any other method which I can use?</li>
  </ul>
  
  <p>Thanks in advance...</p>