I saw a piece of code in a book, which is as follows:
x = 10;
if(x ==10) { // start new scope
int y = 20; // known only to this block
x = y * 2;
}
when it comes to conditions and loops if you don't specify {} then immediate following statement is the only statement that will belong to particular condition or loop
e.g.
x = 10;
if(x ==10)
{
int y = 20;
x = y * 2;
}
both lines get executes only if condition returns TRUE
x = 10;
if(x ==10)
int y = 20;
x = y * 2; // this is not belong to if condition. therefore it will execute anyway