Basic Pascal Tutorial/Chapter 1/Punctuation and Indentation
Sent here from Punctuation and Indentation.
한국어 · Deutsch · English · Français · Български · Русский · 中文(中国) · 日本語
1G - Punctuation and Indentation (author: Tao Yue, state: unchanged)
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
The last statement in a BEGIN-END block, the one immediately preceding the END, does not require a semicolon. However, it's harmless to add one, and it saves you from having to add a semicolon if suddenly you had to move the statement higher up.
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:
program Stupid; const a=5; b=385.3; var alpha,beta:real; begin
alpha := a + b; beta:= b / a end.But it's much better for it to look like this:
program NotAsStupid;
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.
From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 1/Punctuation and Indentation", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Edited on wiki.freepascal.org by 7 people, 2007–2022
From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.
| When | Who | What changed |
|---|---|---|
| Kees | New page: 1G - 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: ... | |
| Kees | ||
| Kees | ||
| Kees | ||
| Vincent | Text replace - "delphi>" to "syntaxhighlight>" (minor) | |
| Jwdietrich | ||
| Ihkim | ||
| FTurtle | ||
| FTurtle | ||
| Trev | Fixed syntax highlighting (minor) | |
| Kai Burghardt | Kai Burghardt moved page Punctuation and Indentation to Basic Pascal Tutorial/Chapter 1/Punctuation and Indentation: tidy up main name space: create subpage hierarchy for basic Pascal tutorial [cf. [[Spe... (minor) | |
| Kai Burghardt | bypass redirects [cf. discussion] | |
| Kai Burghardt | bypass language bar/categorization template redirect [cf. discussion] (minor) |
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
