+ 2
when to use ;
hi i am pretty confuse when to use ; and when to not can anyone clear my doubt .
7 Réponses
+ 3
It goes at the end of every statement, however is not required at the end of blocks.
Ex/
if(condition){
}
// no semi-colon needed here.
The {} is the scope or block of the if statement.
Another example/
void myMethod(){
int a = 3;
// semi-colon needed
} // no semi-colon needed
+ 2
You put them after every statement. Basically everything is a statement that isn't a code block in Java. Code blocks are written with these curly braces { }
code blocks can be class definitions, function definitions, loop blocks, if, else and switch blocks
for example:
class A {
}
or
if(condition) {
}
are code blocks
other than those are statements, like variable definitions, operations with variables, function calls, etc.
i.e.
int a;
double b = 3.0;
a = 2;
a = b;
and so on
+ 1
I don't know about Java, but I think you put that at the end of every line.
+ 1
It still depends whether or not your talking about a block or statement.
Declaration of a String? Yea.
Creating a method with a String return type? No.
Returning a String? Yea.
Best to just know, not for blocks, yes for statements, so you don't need to keep asking yourself.
0
You should use it at the end of the statement. Like declaring variables. At the end of operations like arithmetic int x=5+3;
0
can i use it after Strings?
0
can i use it after Strings?