3 ms·
But `while` doesn't restrict the scope of the variable(s) to just the loop. I believe there was a proposal to add while(int i = 0; i < 100) { ... } as a v
by professoretc 3y ago
But `while` doesn't restrict the scope of the variable(s) to just the loop. I believe there was a proposal to add
while(int i = 0; i < 100) { ... }
as a valid syntax to C++ (which would restrict the scope of i to the loop), as you can already do
if(int i = f(); i > 0) { ... }
but it didn't go anywhere.
- justincredible 3y ago[dead]
- a_e_k 3y agoI'd just use a for with an empty update clause for that: for (int i = 0; i < 100; ) { ... }