Because it's a different
statement.
Think of it like this:
The statement immediately after the "for" statement is an "if" statement. That statement isn't considered to be finished until the end of the final conditional block that it's comprised of.
For example, the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
if (a == 1)
{
b = 2;
c = 3;
d = 4;
}
else if (a == 2)
{
e = 5;
f = 6;
g = 7;
}
else
{
h = 8;
i = 9;
j = 10;
}
|
is all one statement! It's a single "if... else" statement. It may be comprised of many sub-statements, but the whole thing is one big "if... else..." statement.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
if (a == 1)
{
b = 2;
c = 3;
d = 4;
}
else if (a == 2)
{
e = 5;
f = 6;
g = 7;
}
else
{
h = 8;
i = 9;
j = 10;
}
|
So it would be legal to do:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
for(int k=0;k<siff.size()-1;k++)
if (a == 1)
{
b = 2;
c = 3;
d = 4;
}
else if (a == 2)
{
e = 5;
f = 6;
g = 7;
}
else
{
h = 8;
i = 9;
j = 10;
}
|
And, incidentally, that whole code snippet would be considered to be one single for statement, syntactically. Again, it's comprised of several different sub-statements, but it's also one single statement.
The "cout" statement, on the other hand, comes after the "if" statement has finished. It's a separate statement.
Having said all of that,
there are many good reasons to put the braces in anyway (and few good reasons to leave them out).