Where Does One Statement End and the Next Begin?

As Module 2 notes, a program in any language is made up of statements. One of issues confronting a programming language designer is, how does one tell where one statement ends and the next begins? There are three common approaches: statement terminators (used in C++ and Java), statement separators, and statement-per-line.

Most early programming languages, including FORTRAN, COBOL, and BASIC, took the statement-per-line approach. This made a lot of sense in the days before disk drives, when programs were stored in the form of decks of punched cards. Most of these languages had some gimmick for indicating that a statement was continued on the next line. Visual BASIC continues to use the statement-per-line approach.

The second approach is to use some character, usually a semicolon, as a statement separator. The statement separator is then not a part of any statement. The language Pascal used the semicolon as a separator.

The third approach is to use some character, again usually a semicolon, as a statement terminator. The terminator character is then a part of the statement terminated. C++ and Java both use the semicolon as a statement terminator.

What about those "statements" in a C++ program that begin with #include? These are not, strictly speaking, statements in the C++ programming language, so the C++ statement rules do not apply. The #include lines are compiler directives; that is, they provide the compiler with some information that the compiler needs to properly process your program. Each of the #include lines informs the compiler that a particular library is required. There are other types of compiler directives in C++, but we will not encounter them in this course.