4 ms·
int i = 0; while (true) { cout << i; ++i; if (i == 101) { break; } cout << ", "; }
by leni536 2y ago
int i = 0;
while (true) {
cout << i;
++i;
if (i == 101) { break; }
cout << ", ";
}
- Joker_vD 2y agoThat's too much branching. int i = 0; goto main_part; do { cout << ", "; main_part: cout << i; label_for_continue: // yeah, what about "continue"? i++; } while (i <= 100); That's what most for-loops get transformed to during the translation anyhow (with the condition check on the bottom), but writing this by hand? Ugh. Edit: actually, looking at Godbolt, it seems that gcc compiles your suggestion into exactly this shape, while clang splits the first iteration out, into something equivalent to cout << 0; for (int i = 1; i < 101; i++) { cout << ", "; cout << i; } Hmm.