3 ms·
Is the point that any var declared in between the braces automatically goes out of scope, to minimize potential duplication of var names and unintended behavior
by SJC_Hacker 2y ago
Is the point that any var declared in between the braces automatically goes out of scope, to minimize potential duplication of var names and unintended behavior ?
The worst I've seen is old school C programmers who insisted on reusing loop variables in other loops. Even worse, those loop variables were declared inside the loop declaration, which old C standards allowed to visible outside of it.
So they would have stuff like this
for(int i=0; i<10; i++) { ... }
for (;i<20;i++) { ... }
Later versions of C++ disallowed this, which led to some interesting compile failures, which led to insistence of the old stubborn programmers that new compilers simply not be used