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.

Need Your Help

Creating a Base-UserControl

c# wpf xaml inheritance user-controls

I've created several UserControls which got some common Properties. Is it possible to create a base-UserControl from which the concrete ones can derive?

SkyDNS does not work with Kubernetes 1.1.2

docker kubernetes coreos service-discovery skydns

I installed successfully Kubernetes 1.1.2 on CoreOS alpha (877.1.0) will the service files as link https://gist.github.com/thanhson1085/5a005e92245cb2288dee