First, the choice of the first or second option, both in C ++ and in modern C, is made on the basis of whether you need to extend the scope of variable i beyond the cycle. Therefore, out of context, neither the first nor the second option in the general case can be regarded as unambiguously preferable. The question is exactly what you need in this place of the code.
Second, the for loop header allows only one declaration. This means that if your iteration process is serviced by several variables that require different decl-specifier-seq , then you want it or not, but some of them will have to be declared before the loop
unsigned i = 0; for (double *it = container; i < n; ++i, ++it) ...
This limitation can be circumvented in ways like
for (struct { unsigned i; double *it; } i = { 0, container }; ii < n; ++ii, ++i.it) ...
but usually it's not worth it.
iafter the end of the cycle. - ߊߚߤߘi++or++i... - Harrydo ... while... - mymedia