Punctuation and Indentation
Since Pascal ignores end-of-lines and spaces, punctuation is needed to tell the compiler when a statement ends.
You must have a semicolon following:
- the program heading
- each constant definition
- each variable declaration
- each type definition (to be discussed later)
- almost all statements
Indenting is not required. However, it is of great use for the programmer, since it helps to make the program clearer. If you wanted to, you could have a program look like this:
But it's much better for it to look like this:
const
a = 5;
b = 385.3;
var
alpha,
beta : real;
begin (* main *)
alpha := a + b;
beta := b / a
end. (* main *)
In general, indent each block. Skip a line between blocks (such as between the const and var blocks). Modern programming environments (IDE, or Integrated Development Environment) understand Pascal syntax and will often indent for you as you type. You can customize the indentation to your liking (display a tab as three spaces or four?).
Proper indentation makes it much easier to determine how code works, but is vastly aided by judicious commenting.