Program Structure Pascal

Program Structure Pascal - Program Structure The basic...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Program Structure The basic structure of a Pascal program is: PROGRAM ProgramName ( FileList ) ; CONST (* Constant declarations *) TYPE (* Type declarations *) VAR (* Variable declarations *) (* Subprogram definitions *) BEGIN (* Executable statements *) END. Program Structure The elements of a program must be in the correct order, though some may be omitted if not needed. Here's a program that does nothing, but has all the required elements: program DoNothing; begin end. Comments are portions of the code which do not compile or execute. Pascal comments start with a (* and end with a *) . Identifiers Identifiers are names that allow us to reference stored values, such as variables and constants. Also, every program and unit must be named by an identifier. Rules for identifiers: Must begin with a letter from the English alphabet. Can be followed by alphanumeric characters (alphabetic characters and numerals) and possibly the underscore (_). May not contain certain special characters, many of which have special meanings in Pascal. ~ ! @ # $ % ^ & * ( ) + ` - = { } [ ] : " ; ' < > ? , . / | Identifiers Several identifiers are reserved in Pascal as syntactical elements. We are not allowed to use these for our identifiers. These include but are not limited to: and array begin case const div do downto else end file for forward function goto if in label mod nil not of or packed procedure program record repeat set then to type until var while with Constants Constants are referenced by identifiers, and can be assigned one value at the beginning of the program. The value stored in a constant cannot be changed. Constants are defined in the constant section of the program: const Identifier1 = value ; Identifier2 = value ; Identifier3 = value ; Constants For example, let's define some constants of various data types: strings, characters, integers, reals, and Booleans. const Name = 'Tao Yue';...
View Full Document

Page1 / 21

Program Structure Pascal - Program Structure The basic...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online