What does "empty string with semicolon" mean in C #?

I came across this code and was wondering why the C # compiler is not throwing any warnings or errors. Strictly speaking, I think I am trying to accomplish anything, what is it really really? (for blank lines)

semi colons on blank lines

+3


source to share


1 answer


This is an empty statement . It is useful as a loop body:

while(!Condition()) ;

      

More common in a for-loop, where the body of the loop is completely embedded in the head of the loop.

Go to the last item in the linked list:



Node current = head;
for (; current.Next != null; current = current.Next) ;
return current;

      

This looks a little annoying, and I usually prefer to write a longer but more readable loop. C ++ people tend to insert stuff in the header of the loop often.

I'm sure this can come in handy in code generation scripts too.

+4


source







All Articles