Comment on What will happen if we put a semi-colon after a for loop in C++?

plistig@feddit.de ⁨1⁩ ⁨year⁩ ago

A semicolon ends a statement, and semicolon is a statement on its own. One that does nothing. That’s why you can write int i; for (i = 0; i < 3; i++); to set i = 3. You can use that pattern to find something in an iterator, etc. But I would prefer int i = 0; while (i < 3) { i++; } for readability.

source
Sort:hotnewtop