The Empty Statement

To ease into the subject of statements gradually, let’s start with the most mind-blowing of all: the empty statement. Written as a simple semicolon by itself, it’s rarely useful. One of the only cases where this comes in handy is when you’re writing some kind of “message pump,” a loop that calls some processing method until it returns false to indicate no further messages are to be handled:

while (ProcessMessage())    ;

I predict most readers won’t ever have to write such a loop anymore—we’re well beyond the manual message pumping required in classic Win32—but it’s good to know about its existence in case you encounter this kind of code. In fact, you could eliminate the use of the preceding empty statement by using an empty ...

Get C# 5.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.