For if statement. Curly brackets are necessary? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

For if statement. Curly brackets are necessary?

21st Jan 2017, 3:53 AM
Ravikumar Ronad
Ravikumar Ronad - avatar
2 Antworten
+ 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.
21st Jan 2017, 4:51 AM
Ahmed Elzoughby
Ahmed Elzoughby - avatar
+ 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.
21st Jan 2017, 8:32 AM
ifl
ifl - avatar