New course! Every coder should learn Generative AI!
Try a free lesson+ 12
Are curly braces necessary in one-line statements ?
No!
But they are recommended. If you ever expand the statement you will need them.
This is perfectly valid:
if (condition)
statement;
else
statement;
Braces are used where optional:
Braces are used with if, else, for, do and while statements, even when the body is empty or contains only a single statement.
for (iteration condition)
statement;