The C# language specification defines the empty-statement grammar production, which allows me to do something like this:
static void Main(string[] a
So some genius could write for(;;)
instead of while(true)
. Like for an interview test.
C# inherits a lot from the C family, where you can do things like
for (i = 0; i < n; v[i++] = 1);
or
while (testSomeCondition());
That is, run a loop with an empty body where the "meat" is inside the brackets.
While one can debate about their merits and dangers, these are pretty common programming idioms in the C programming world, so this backward compatibility makes it easier for C/C++/Java programmers to learn C#.
This is an assumption but I would assume it goes to the base grammar for the compiler. Relating it to set theory the "empty set" is inside every single set. That the ; really is to define a set of lexical operations which always must define the ; which also would accept the base case which is empty statement.
if (b1)
if (b2) else;
else
//code
withoud this ; this will be painful. but this is not best way to write ifs also. but acceptable.
For what it's worth, a good rule of thumb is that you should have stepped through in the debugger every line of code you write, at least once for each possible execution path
ref: Possible mistaken empty statement
Good practice or not, some people use this:
while (!SomeCondition)
; // <-- body of the while loop is an empty statement