All courses in any programming language seem to start with the 'Hello World' program, and we don't see any reason to deviate from that well beaten track : (* Hello World Pascal Program *) program hello; begin writeln ('Hello World'); end. (* End of Program *) When run from the command prompt on your system, this program simply says 'Hello World' and terminates. Let's go through it line by line : (* Hello World Pascal Program *) Any text that occurs between a "(*" and "*)" is a comment and is ignored by the pascal compiler. It can contain freeform text and is usually used to make the program more comprehensible to the reader. program hello; This line, which identifies the name of the program as 'hello' is purely decorative in modern versions of pascal. It is still widely used for historic reasons related to ensuring backward compatibility with early versions of the pascal compiler. begin The begin statement indicates to the compiler that the processing which the program is to execute is to follow. Usually, before a begin statement will be found variable and constant declarations, subroutines and comments. In this case, the 'begin' statement indicates the start of the main body of the program. It can also indicate the start of a block of grouped commands, for example, where a group of commands is to be executed together as a result of a for or if command writeln ('Hello World'); The writeln command writes a line of text to the output device, usually the computer screen. The text to be written is then passed as a parameter to the command, in quotes and delimited by brackets. As with all pascal commands, the writeln command is terminated with a semicolon ";". After writing the text passed to it as a parameter to the screen, writeln writes a newline character to the screen, causing the next line of text to be written on a new line. If you do not wish to 'throw' to a new line, use the write command instead. end. The end command indicates the end of the main body of processing which commenced with the begin command. Where end is the last line of the program, indicating the completion of the block of code initiated by the begin command, it is always followed by a period (".") Where the end command indicates the end of a block of code which is not the end of the main sequence of commands, e.g. when it is completing a block of code relating to an if or for statement, it is not followed by a period. (* End of Program *) Once again, any material between the "(*" and "*)" is treated as a comment and is ignored by the compiler. That's the end of your first Pascal program!
Hosted by www.Geocities.ws

1