Note that in a for loop there are no 'constraints' as to what can be performed in each of the 3 parts - unlike Basic. Simply:
1 2 3 4
|
for (a; b; c)
// d
// f
| |
a statement is executed once. It may include a variable definition.
b condition is evaluated at the beginning of each of the loops. This can be any statement that can be evaluated to a bool (true/false, 1/0). If this evaluates to false (0) then statement f following the for loop is executed.
d statement is executed (if present) if the b condition is evaluated true (1). This can be a compound statement.
c is executed after d (even if d is not present).
b condition is evaluated again - and the loop continues...
All of a, b or c are optional. They need not be present if not required - although the 2 ; are required. If b is not present, it is assumed to be true.
This gives great flexibility in the use of the for statement (and abuse in making b and c almost unreadable!).
Also note that in C/C++ there is the , operator.
This is one statement - consisting of 3 expressions x y z
x is executed, then y, then z. The result of the statement is that obtained from z. Using this , operator can be used anywhere a statement is required - but is especially useful for statement c in the for loop.
https://en.cppreference.com/w/cpp/language/for
https://en.cppreference.com/w/cpp/language/operator_other