Why are multiple semicolons allowed? [duplicate]

That’s because the semicolon, when used alone, represents the empty statement.

The documentation says:

The empty statement consists of a single semicolon. It does nothing
and can be used in places where a statement is required but no action
needs to be performed.

And provides the following example:

void ProcessMessages()
{
    while (ProcessMessage())
        ; // Statement needed here.
}

Of course, you can execute as many empty statements as you want in sequence, and nothing will happen.

Leave a Comment