Structure of programs

From Delphi Pascal wiki
Jump to navigation Jump to search

Programming language PASCAL is a procedural language. Structure (how i can definite what program is about) was definited and it must be observed.

Before you start to work, you must know what kind of program do you want to make, how it will communicated with a user and what kind of variables it will need. All this setting programmer must definite in a 1st part of program, its a a definition part. In there we write about used library, next we will defininte a program variables, and a kind of variables.

THIS IS A ROUGHLY , HOW A PROGRAM CAN LOOKS LIKE : Fat words, are that, which are constantlz required. The other are for programmer.

PROGRAM name_of_program;
USES used_library(one or more);
CONST definition_of_program_constants;
TYPE definition_of_new_kinds_of_variables;
VAR definition_of_variables;
BEGIN    { main_begin - beggining of program }
   command_1;
   command_2;
   ..
END.    { main end - ending of program }

In the part between BEGIN - END. Are commands, which are making progress in a program .This part cannot work without a definition part in this BEGIN - End. part , which have all settings of a program in a TP.


The Definition part.

PROGRAM name_of_program;
Word program says, its a program in TP. Next we write a name of program. Itis good to write a name, about a program work.


USES used_library;
Programming language in TP has in his begginings a few of a primary commands. It was easy to learn that commands... beacause there was really only a few commands, but it was hard to make any program with this minimum. So there was chance to make new and new commands, basing the old wrods, to make a programming easyer. It was for the programming beggining good, but a few years later no one can was on rhat commands. So there was a idea, to get a commands to their libraryes, how it workd in a really library So if we want to programm a printer we use a library PRINTER. If we going to make a graphic program, we use a library of GRAPH.


So before we begin, we must now what king of library we want to use.

HERE ARE SOME OF THE BASIC LIBRARY:

CRT - work with a text editor, work with a keyboard, PC
DOS - DOS functions (Windows)
Graph - graphic commands for work in a graphic editor
PRINTER - work with a Printer
There is a more and more of a library.


CONST constants_of_program;
Like all, program have a properties, which are constant. For us are constants name or birthdate. If we want make program using any constant, we must give it any name and set it for any ammount ... That all in this part of program.


TYPE definition_of_new_variables;
This part is a part of the another chapter.


VAR definition_of_variables;
Every program need for work anything, for saving his progress, numbers or any words, sentences or any simple characters. For this, we are using a variables.


Before we can use them, we must definite them. Tell to computer: This is my variable, it calls X and i want to save a numbers to it. For better understand, imagine a shelf with bottles(memory of our PC). In the shelf are three kinds of bottles-every kind for one kind of liquid. In agreement with a kind of liquid, we chose kind of bottle. For differentiate bottles i get a marks on them.


Variables are like that bottles. Name of variable is taht mark on the bottle, kind of variable is a kind of bottle. Like on a shelf we can bind this variables or different them.
Example: var x:integer;


Where to go: Content | Variable type