Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

When writing an if-statement, is it better coding style to use a braces?

+10 votes
asked Sep 1, 2016 in CSC 285 (F16) by Kevin Barbian (100 points)

1 Answer

+5 votes
Yes indeed, because you might want to add more statements, and that would sometime messed up with large codes.

Furthermore, you want to clearly separate statements. For example, with

if (k == 0) System.out.println(); System out.print("haha");

you might mistakenly think that the after statement is inside the if-statement.
answered Sep 1, 2016 by Minh Ta (100 points)