C6295

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at C6295.

warning C6295: Ill-defined for-loop: <variable> values are of the range "min" to "max". Loop executed indefinitely

This warning indicates that a for-loop might not function as intended. The for-loop tests an unsigned value against zero (0) with >=. The result is always true, therefore the loop is infinite.

The following code generates this warning:

void f( )  
{  
  for (unsigned int i = 100; i >= 0; i--)   
  {  
    // code ...  
  }  
}  

To correct this warning, use the following code:

void f( )  
{  
   for (unsigned int i = 100; i > 0; i--)  
   {  
      // code ...  
   }  
}  

Show: