CS.STMT.DO.BLOCK

Body for do statement should be a block.

The body of a do statement should be followed by a block statement.

Vulnerability and risk

If you omit the braces {} in the body of a do statement, a careless programming error may occur.

Mitigation and prevention

Make sure to use curly braces in the body of a do 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 testNGDo(int some_number)
         {
 
             int i = 0;
             do
                 i++;
             while (i < some_number);
 
             int j = 0;
             do
                 ;
             while (j < some_number);
 
         }
 
         public void testOKDo(int some_number)
         {
 
             int i = 0;
             do
             {
                 i++;
             } while (i < some_number);
 
             int j = 0;
             do
             {
                 ;
             } while (j < some_number);
 
         }
     }
 }