when to use ; | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

when to use ;

hi i am pretty confuse when to use ; and when to not can anyone clear my doubt .

21st Jun 2017, 5:45 PM
Ayushman Mishra
Ayushman Mishra - avatar
7 Answers
+ 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
21st Jun 2017, 5:56 PM
Rrestoring faith
Rrestoring faith - avatar
+ 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
21st Jun 2017, 5:59 PM
Eligijus Silkartas
Eligijus Silkartas - avatar
+ 1
I don't know about Java, but I think you put that at the end of every line.
21st Jun 2017, 5:48 PM
Terck
+ 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.
24th Jun 2017, 4:49 PM
Rrestoring faith
Rrestoring faith - avatar
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;
23rd Jun 2017, 4:52 PM
Bheeshma
Bheeshma - avatar
0
can i use it after Strings?
24th Jun 2017, 9:38 AM
Gopal Biswas
Gopal Biswas - avatar
0
can i use it after Strings?
24th Jun 2017, 9:38 AM
Gopal Biswas
Gopal Biswas - avatar