5.71 New block scopes for selection and iteration statements in C99

In a for loop, the first expression can be a declaration, like in C++. The scope of the declaration extends to the body of the loop only.

For example:

extern int max;
for (int n = max - 1; n >= 0; n--)
{
    // body of loop
}

is equivalent to:

extern int max;
{
    int n = max - 1;
    for (; n >= 0; n--)
    {
        // body of loop    
    }
}

Note:

Unlike in C++, you cannot introduce new declarations in a for-test, if-test or switch-expression.

Non-ConfidentialPDF file icon PDF versionARM DUI0472M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.