CS.CONSTCOND.DO

The condition of a 'do' statement is always true or always false.

Example 1

Copy
  class Increaser {
      void Increase() {
          int x = 3;
          do {
              x++;
          } while (3 < 10);  // defect - the condition is constant
          do {
              x--;
          } while(false);    // Ok - typical usage of 'do' constructs when a user to organize a code block
         do {
             return;
         } while(true);     // Ok - typical usage of 'do' constructs when a user to organize an infinite loop
     }
 }

Security training

Application security training materials provided by Secure Code Warrior.