3.1 Statement Sequences

Although a few machines can run two or more programs simultaneously, most modern computers execute programs as sequential steps (one after the other). That is, programs consist of commands written in a particular order, and the compiler for the programming notation preserves this order when translating into machine-readable code. Chapter two introduced several examples of Modula-2 commands or statements. Examples in that chapter included numerous examples of sequences of such statements. Here is another:

  WriteString ("This program computes the area of a square");
  WriteLn;
  WriteString ("It was written by");
  WriteLn;
  WriteString ("Nellie Hacker");
  WriteLn;
  WriteString ("for CMPT 141");
  WriteLn;
  WriteString ("Assignment #2 Due 1992 09 22");
  WriteLn;
  WriteLn;

Figure 3.1 summarizes the syntax of the statement sequence, and details the statement types encountered thus far. The second diagram is incomplete, of course. It will be added to in this chapter and for several chapters to come. A complete version is in Appendix 2.

Notice that a statement need contain nothing at all! Several consecutive semicolons therefore constitutes a valid statement sequence, though it is a rather uninteresting one. Thus, (redundant) semicolons are allowed before an END (or in similar situations,) where they are not required because they are not separating statements. This can be helpful to the programmer who frequently goes back to add new statements to the end of a sequence, and just as frequently forgets to insert a new semicolon before the first of the new statements. If the sequence ends in a semicolon, one need not remember to put one in when extending it.


Contents