Why don't these Semicolons Produce an Error?<>
This question already has an answer here:
That is known as the empty statement and it is valid.
An empty statement does nothing.
It doesn't have many uses
while (checkCondition()) // may have some side effects ;
A semicolon is used to terminate statements indicating the end of a statement
so when you say
int i=5; ;
it just means that that is an empty statement. Though there is no use of it, it is not considered as an error as it simply denotes an end of statement which is empty.
This is how compiler works.
When compiler compiles your code it follows certain rules called Context Free Grammar, which is defined differently for different languages.
In the C programming language, there might be a rule such as
statement -> (optional_other_stuff) + ';'
which implies each statement must end with a semicolon.
In other words, missing semicolon will make the statement unrecognizable by a compiler, but extra semicolon merely considered as an empty statement for compiler
Its empty statement and when you compile the class it is removed from it.
So it make no difference.