I was working on a project and unintentionally ran into the semicolon that ended up being inserted well after a if
. I was intrigued because Visual Studio did not point as an error, and when trying to compile the project I was successful.
The code looks like this:
if(alguma_coisa)
{
//Bloco lógico
};
Motivated by curiosity, I realized that you can also enter a semicolon at the end of a loop like while
, for
, and foreach
.
I showed it to a friend and he revealed the possibility of inserting the semicolon several times in sequence on the same line as the following:
if(alguma_coisa)
{
//Bloco lógico
}; ; ; ; ; ;
And yet the project is compiled without any problem.
Should not a compile error be generated?
Why is this allowed?