Null Statements

Top  Previous  Next

The null statement does nothing. It consists of nothing, and it compiles into nothing. It is useful because in some circumstances we want to do nothing. An example of this was shown with the "other" part of a "case" statement. Here are some more examples:


        for I:= 1, 1000 do [];          \Kill some time

        while not Strobe do;            \Wait for Strobe to be "true"

        repeat until KeyStruck          \Another form of wait


Each of these statements contains a null sub-statement.


Null statements are frequently used as a coding convenience--a kind of XPL0 slang. For example, these two blocks compile into exactly the same code:


        begin                   begin

        X:= X + 1;              X:= X + 1;

        Y:= Y - 1               Y:= Y - 1;

        end                     end


Note that the block on the right actually contains three statements: the two assignments and a null statement after the second semicolon.


This is convenient because now we can simply insert or delete statements by inserting or deleting lines and not worry about a semicolon on the previous line. Here you might think of semicolons as statement terminators, but they are actually statement separators.


Unless you understand the concept of null statements, you can become confused by semicolons, especially in if-then-else statements. A semicolon is used to separate statements and procedures and to terminate declarations.