Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

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.

Example

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 ...
   }
}

Community Additions

ADD
Show:
© 2015 Microsoft