The structure of the Pascal program: programming for beginners
The most accessible programming language forBeginner is Pascal. This is due, at least, to the fact that it is studied in the upper grades of general education schools, as well as at the first courses at the university. It is used as a base for mastering many other languages. However, as the main for the development of its use is now irrational, as the technical equipment is far advanced.
Now there are a lot of means,which preserve the syntax. They differ only in the programming environment of a language such as Pascal. The structure of the program will be studied in the process of the article. As a rule, familiarity with programming begins with the program "Hello world!".
History of the language
In the light of Pascal appeared in 1970 thanks,oddly enough, Niklaus Wirt. The name is given in honor of Blaise Pascal - a great man originally from France. This is justified by the fact that the scientist created the first machine in the world, which was able to add and subtract numbers.
The development of the language was conducted from 1968 to 1969. The first mention appeared in 1970. The creator, presenting his "child", emphasized the style of programming, as well as the input of data in Pascal. The structure of the program was also developed by Wirth. It has a simple syntax and semantics. The direct "descendant" of Pascal is the language of "Modula-2". Wirth was also its developer.
It should be noted that the structure of the program is not so complicated in this language. In Pascal, the author has laid down the use of only three main points - the title, description and operator.
- Header. Here you need to specify the name of the program, but this item is not the main one. It is created only if the developer wants. Mostly it depends on the programming environment. In Turbo Pascal it is not needed. But in ETH it is necessary to create a string without fail. Only numbers, letters and the underscore "_" are allowed.
- Description. This block specifies all available variables (arrays), labels, and so on.
- Operator. The structure of the Pascal program includes the description of the operators in brackets BEGIN-END.
How many will be in one line,irrelevant. The main thing - after the end of each team put a special symbol - a semicolon. In addition, the language is case-insensitive: there is no difference between the operator Var, vAr and vaR.
Syntax and semantics
The main role in working with the programming environment is played by the alphabet. It should be remembered that it consists of:
- Latin characters, both lowercase and uppercase;
- a space;
- Arabic numerals;
- mathematical signs;
- Limiters (their list includes a point, comma, etc.);
- service words (operators).
The structure of the program on Turbo Pascal does notdiffers from the structure on PascalABC. The difference is in their external data, nothing more. Specifying a name for a variable and other types, it is necessary to remember that the name should not begin with a number, the underscore can stand in any position, and from the alphabetic symbolism it is allowed to use only letters of the Latin alphabet.
Comments to the lines are enclosed in curly brackets or in round ones with an asterisk: (* .. *).
The structure of the Pascal program also implies the consideration of objects such as data types. They come in three forms:
- logical (truth and falsehood);
- numeric (Arabic numerals);
- symbolic (using a, b, c, etc.).
At the same time, the second type is divided into subtypes: integer and real. They correspond to certain operators: Integer and Real, respectively. Symbols are also divided into single characters and lines. These are data types, such as (in the first case) a 1, a or A, and (in the second) whole phrases or an expression. In the program they are written under the names Char and Spring.
Values also have their own classification. They are divided into constants and variables. The difference between them is significant. The first implies the meaning of the letter, which does not change during the execution of the program. A variable is assigned a value in the course of execution using a special character - a colon.
In order to achieve full understandingprogram and all its processes, the comment function is used. They, as already mentioned above, are placed in curly brackets. This is especially important if you are viewing a newbie code. Because using this option, you can easily find an error in an already finished program, relying on what is written in the comments. Moreover, they will help the developer to quickly understand the security code.
The structure of the Pascal program allowsTo assign comments to the data structure specified in the second block. There it is necessary to enter the text, which will contain the purpose of each operator and how it is used in the future.
Beginners will be guided in brackets BEGIN-END comment next to them. Especially it will be useful in a program oriented to cycles. So it will be easier to understand which block of operators is complete.
Comments can not be read by the programming environment, so they can borrow any number of dates and are not limited in alphabetical order.
The structure of the Pascal program has its ownpunctuation, however, this is not surprising. The most used sign is a semicolon. It is placed after each description of the blocks Label, Type, Const, Var, etc., but the sign is not needed after the most determined word. After Begin it is not installed; After END is put only in the event that the program is not yet completed. In code where there are loops and, accordingly, are used by Then and Else, after these words a semicolon is not needed.
At the end of the program, after END, you need to set a point, otherwise the programming environment will not understand that the code is completed.
Input and output of data
The structure of the Pascal program allows you to enter data in three different ways. Among them:
- Using the Readln, Read statements.
- Using an assignment symbol, use a colon.
- The constant. In this case, the data is entered in the var parameter.
The output of the received information can be made atthe help of the bindings of the Write and Writeln operators. In some cases, it may be absent, but this only means that it is already embedded in the method of receipt.