What the…

Why is it do {…} while(); with a semi-colon at the end in C, while simple while and for don’t need one / shouldn’t have one.

@lanodan In C, braces are not part of the loop syntax, they are an independent entity to group several lines. It is just very convenient to loop over a series of lines rather than one.

For and while loops do need semicolon when they are not followed by braces. E.g:
while (a++ < 10);
So it's the braces what remove the need for a semicolon. It just happens to be the most common setup.

Follow

@roobre @lanodan It alone is even sometimes a syntax people use

while(callMeTenTimesAndIReturnFalse());

· · Web · 0 · 0 · 0
Sign in to participate in the conversation
Game Liberty Mastodon

Mainly gaming/nerd instance for people who value free speech. Everyone is welcome.