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
4 ответов
+ 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.
+ 2
Thanks
+ 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
}
+ 1
Thanks