Basic Pascal Structure
- program program_name;
Uses WinCRT;
Var
- {Variable declaration}
- {Program instructions}
- There a reserved words in pascal. These reserved words are explain in the table below:
Reserve WordDefinitionProgramThe first word in a pascal prgoram. It is then followed by the program name. For example:Program program_name;UsesIt allows the program to do certain operations. For exampleUses WinCRT;This allows the program to display to the screen and accept values from the keyboardTypeStates the area for defining subranged data types.ConstStates the area for declaration of constants.VarStates the area for declaration of variables.BeginIndicates the beginning of a programming instructions.End.The last word in a pascal program. This word pronounciates the end of the pascal program.
Variables and constants.
- Variables and constants are like cups in memory. They hold the designated type of data desired by the programmer. Variables allow the option for its content to vary. Variables are like a cup that one can use to pour in juice at one time, water at another time and wine another. While constants are are set and can not change its content. Like a cup that its content has been insert then sealed, it content stay permanent and can not change.
- In pascal variables can not just be used at will. First these variables need to be created before they are uses. This creation of these cups in memory is called the declaration of variables process. To declare these variables we follow the following syntax.
- Var
- variable_name:data_type;
- length:integer;
- width:integer;
- price:real;
- Just like Variables constants are need to be declared. The syntax is as followed:
- Const
- constant_name=Value;
VAT=0.17;
Message='Fail';
- constant_name=Value;
Declaration of Variables in Pascal
Declaration of Constants in Pascal
Input and output in Pascal
- In pascal we can accept values from the keyboard and display values to the screen. To do this we use the commands read and readln for input. While for output we can use the commands write and writeln.The syntax is as followed:
- writeln('Enter a number');
This will display the message Enter a number to the screen - readln(num);
This will accept a value from the keyboard and store it in the variable num. - writeln('The number you entered is ',num);
This will display to the screen The number you entered is 7. It will display the message followed by the content that is in the variable num.
No comments:
Post a Comment