0

how.do you remember when do use curly braces {} vs a semicolon ; when programming.

how.do you remember when do use curly braces {} vs a semicolon ; when programming. I dont know if their is something programmers can do to remember as general rule. thanks

9th Nov 2019, 4:55 PM
Making A Change
Making A Change - avatar
4 odpowiedzi
+ 6
Having semicolons you don't need is usually fine. Using braces you don't need is also usually fine. Therefore, I'd suggest assuming you always need them. End every statement with semicolon. Make the braces a permanent part of the statements that can use them. For example the while statement: while (condition) {statement;}; Once you get to the point you understand it, you may eliminate the unnecessary stuff.
9th Nov 2019, 6:17 PM
John Wells
John Wells - avatar
+ 2
Thanks
9th Nov 2019, 6:26 PM
Making A Change
Making A Change - avatar
+ 2
In java: every statement needs a semicolon int a = 4; System.out.println(); Curly braces for blocks: loops, switch, methods, classes... In short: some lines of codes which are inside the curly braces belongs to the loop or method or whatever. while(){ //some lines of code } public void foo(){ //some line of codes } public class Program{ //some code }
9th Nov 2019, 7:27 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Thanks
9th Nov 2019, 8:20 PM
Making A Change
Making A Change - avatar