+ 1
Doubt about curly braces in if else
if sometimes we use if else, we put braces in if but not on else why does it work for example if{ ... } else if { } else
3 Antworten
+ 3
If , if or else if or loops only contains one statement than {} can be omitted.
Your code will be fine and there will be no error.
However its good practice to wrap them inside {}.
Hope this helps ☺️☺️.
0
you should always put curly brackets after else
0
Vivek Mishra In if,if else when you omit braces then it wll read only one line so braces is used when we want to execute more than one line so if u hve to execute one line its depend on u u want to put braces or not thats why error is not coming
for e.g.
int a=5;
if(a>5) // condition is false
System.out.print("hello"); /* not printed as condition is false */
System.out.print("hii"); /* it wll not effected by if statement nd it wll executed */
// hope u get it