Long story short, if you leave out the block C control structures (while, if, for, else...) they will generally iterate on or execute the next statement. This is a bad idea. It turns out you can put a lot of things in place of the block in a while
or for
loop, most of them are also a bad idea. Let's go to the C99 standard.
6.8.5 Iteration statements Syntax
iteration-statement:
while ( expression ) statement
do statement while ( expression ) ;
for ( expressionopt ; expressionopt ; expressionopt ) statement
for ( declaration expressionopt ; expressionopt ) statement
Notice they all take "statements" not "blocks". What's a "statement"?
6.8 Statements and blocks Syntax
statement:
labeled-statement
compound-statement
expression-statement
selection-statement
iteration-statement
jump-statement
Long story short, a "compound-statement" is a block, an "expression-statement" is a single expression, and we'll skip the rest right now. This is a while loop with an expression-statement.
while( condition )
do_something;
This is a while loop with a compound-statement.
while( condition ) {
do_this;
and_this;
and_this;
}
It's a good idea to always use blocks, even for one line. Why? Because you can easily fool yourself into thinking you're looping over statements you're not.
while( condition )
do_this;
and_this;
and_this;
Those last two statements sure look like they're part of the loop, but they're not.
A common mistake is to write something like this:
if( condition )
do_this;
else
do_something_else;
and_also_this;
and_also_this
will always be executed.
It is much safer to always include the block.
The main question has already been answered elsewhere.