+ 2
If/else statements
Whats the difference of using curly brackets and not using curly brackets. Why would you need to use them?
3 Réponses
+ 3
we can omit the curly braces after if-else statements, or after any loop. If we do not use curly braces then only one statement after the if-else or loop will be considered under that block. For example
+ 2
if(condition) { Line 1 Line 2 } if(condition) Line 1 Line 2
+ 2
In the first case, the Line1 and Line2 both are in the if block. But in the second condition, the Line1 is in if block but Line2 is not in if block. So we can omit curly braces only there is a single statement under if-else or loop.