0
For if statement. Curly brackets are necessary?
2 Respostas
+ 1
It is not necessary only when you have one statement to execute after the if, else, while, for, do and else if expressions. For examples:
if(expression)
one_statement;
if(expression)
one_statement;
else
one_statement;
But when you have more than one statement it is necessary to put it.
+ 1
if there is no '{ }' after if, then only the one next statement after if is executed when the condition is true.
if there is no '{ }' after else , then only the one next statement after else is executed when the condition is false.
also if there is no '{ }' but more than one statement between if and else, there will be a compilation error.