CS.STMT.WHILE.BLOCK

Body for while statement should be a block.

The body of a while statement must be a block enclosed by {and}.

Vulnerability and risk

If you omit the curly braces while in the body of a while statement, a careless programming error may occur.

Mitigation and prevention

Use curly braces in the body of the while statement.

Example

Copy
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace kmcustom
  {
      class C18
     {
         public void doSomething()
         {
 
         }
 
         public void testNGWhile(int some_number)
         {
 
             int i = 0;
             while (i < some_number)
                 i++;
 
             int j = 0;
             while (j < some_number) ;
 
         }
 
         public void testOKWhile(int some_number)
         {
 
             int i = 0;
             while (i < some_number)
             {
                 i++;
             }
         }
     }
 }