[Solved] What is the scope of a for loop without braces in C++


Any control structure (if, for, while, etc.) without braces applies only to the next statement. The second example is equivalent to the following:

for (int i = 0; i < 10; i++) {
    continue;
}
cout << i << endl;

Note that it’s often considered bad style to have control structures without braces, because people can forget to add the braces if they add another line, and it can lead to the dangling else problem.

2

solved What is the scope of a for loop without braces in C++