Basic Pascal Syntax
What is Syntax?
Rules that govern the programming language.
1. Starting your Pascal Program
Program program_name;
Eg. Program add_two_numbers;
2. Adding your name and information to program
USE COMMENTS – Place text between { }
Eg . {Dominica Anderson, October 23, 2014}
THIS WILL NOT BE PART OF CODE
3. Opening the library of files that contains clear screen code
USES CRT;
NB. Not case-sensitive
4. Declaring Variables
What are Variables?
Locations in memory that the content can be changed e.g. firstname.
Locations in memory that cannot be changed during program are called constants e.g pi.
VAR variable_name1, variable_name2, variable_name3:Data_type;
e.g.
VAR NUMBER1, NUMBER2, NUMBER3, SUM: INTEGER;
5. Start and ending the program.
Begin
STATEMENTS TO EXECUTE
End.
6. Output Statements and Prompts
Output statement display text to the screen. You must always instruct or prompt user to
enter information needed by input using output statements.
WRITELN(‘TEXT TO BE DISPLAYED’);
WRITELN(‘TEXT TO BE DISPLAYED’, VARIABLE);
WRITE(‘TEXT TO BE DISPLAYED’);
Eg. WRITELN(‘Enter the first number’);
WRITELN(‘The average is ‘, AVERAGE);
WRITELN will place the cursor on a new line after displaying the text, WRITE will not. Cursor
will be on the same line as text.
7. Input Statement
Use input statement to collect data from a user (keyboard) and store it in a variable.
READLN(VARIABLE);
Eg.
READLN(NUM1);
8. Assignment Statements
Assignment statements are used to store data in a variable (memory location)
VARIABLE_NAME := DATA ;
EG.
NUM1 := 20;
SUM := NUM1 + NUM2 ;