Computers, Programming
"Pascal" is ... Language "Pascal" for beginners: description
In the vastness of the Internet, you can find a lot of programs in the language of "Pascal", but it is much more difficult to understand the principle of how they work and how they are arranged. Let's study the basics of programming together!
Algorithmic language: basic concepts
In colloquial speech, we use the basic units: symbols, words, phrases and whole sentences. Algorithmic language also has a similar structure, only its components are called differently. We are talking about elementary constructions, expressions and operators. All these units form a hierarchical structure, since each subsequent element is formed from the previous one.
The symbols of an algorithmic language are indivisible atoms used for writing code.
Elementary designs are minimal units that have their own meaning.
Classical language expressions are formed from the two above units and specify the rules for finding the required value.
The operator is responsible for describing a certain transformation, which is mandatory for the correct execution of the program. They can be several, if necessary - the program must perform a complex operation. In such situations, they are combined into a block or a composite operator.
Language "Pascal"
There are a large number of algorithmic languages. "Pascal" (for beginners there are separate manuals) is one of them. Its alphabet consists of numbers, letters and special symbols. Here is their list:
- 26 Latin upper and lower case letters ;
- An underscore;
- Ten digits;
- Limiters;
- Signs of operations;
- Specifiers;
- Reserved by the system (service) words.
In addition to the elements listed above, a "space" belongs to the set of basic ones, which can not be used inside the reserved expression and double symbols construction.
Elementary constructions of the language
"Pascal" for beginners includes strings, numbers and names.
The numbers used in the code of the programming language in question are usually written in the decimal system. They can be either real or integer, which is usually referred to without a decimal point. If the number is positive, its sign can be omitted.
"Pascal" is an algorithmic programming language in which strings are a sequence of characters enclosed in apostrophes. If you need to use the apostrophe itself, then this symbol is worth mentioning twice.
A name is a sequence that begins with a letter and can contain numbers. Identifiers are called labels, types, constants, functions, procedures, variables, objects, and even modules. By forming identifiers, you can use the underscore character. A name can have a mass of characters, but the compiler will only read the first 63 characters. "Pascal", the description of which may seem so difficult, is not so terrible, so do not rush to get scared and close the browser page!
As language identifiers, it is forbidden to use the standard names of constants, procedures, types, files, functions, and utility expressions.
Improve the visibility of the code will help gaps, but remember that they can not separate names and numbers in the middle.
Syntax of algorithmic language
Each line must end with a semicolon in the program written in the language we are considering ("Pascal"). Informatics teaches schoolchildren and students, and you can realize these rules yourself!
A semicolon (;) is a conditional signal that indicates the end of the current line and the need to switch to a new one. But the exception can be service commands: const, var, begin and others.
The end statement closes the program, so the dot is always put after it. Sometimes the code can contain several attachments, then the beginning and end of the block will be separated by a semicolon.
To assign a variable to a specific value, the colon must be preceded by a colon. For example, you go to set n = 13, and in the code it will look like n: = 13.
If you master these rules, you can quickly learn how to write the code of the program without syntax errors.
Classical operators of the language "Pascal"
You can program duplicate code snippets of a future application and perform any actions with it in various ways. But the language "Pascal" uses for this various operators. We can not consider all of them, so we will deal with only a few.
For example, using the selection operator, you can select one of the alternative ways of the program's progress. Parameter in this case is an expression of the ordinal type. But there is one nuance: this selection key can not belong to the type string or real.
Assignment, conditional, compound and empty operators exist, as well as many other useful attachments. Knowledge of only some of them allows you to write code with excellent functionality. Operators should not be abused, because their large number makes the program difficult to debug by a compiler, confusing and very difficult to perceive by strangers.
Assignment operator
This expression has the form of a colon and an equal sign. It is used to assign a specific value to a particular variable. It is important to remember that the type of the expression and the variable must match if they do not refer to the whole and the actual type, respectively. Only in this situation there will be a direct transformation.
Compound Operators
"Pascal" is a programming language that uses sequences of arbitrary program operators, enclosed in special brackets. It is a question of compound constructions, limited by the words begin and end. This is an important tool of the algorithmic language, with the help of which it becomes possible to write code using structural methodology.
The operators of the Pascal language, which are part of the composite structure, can be completely different, because there are no restrictions. The depth of nesting can also be different.
Conditional programming language operator
This component provides an opportunity during the program to check the specified condition and perform an action, depending on the results of its passage. Thus, a conditional command is one of the means of forming branches during the execution of calculations.
The structured conditional statement looks like this:
IF
In this expression, else, then, and if are reserved words, the condition is a logical expression with arbitrary content, and operators are any commands of the programming language used.
Structure of the program code
The title, sections of statements and descriptions are key components of the application written in a language such as Pascal. Informatics allows you to fully study these elements and learn how to use them correctly.
The header, as a rule, contains the name of the code. For example, Program MyFirst.
In the description section, the connected libraries, modules, labels, constants, types, variables, a chapter of the description of functions and procedures can be listed.
The module description section contains inside the names of the connected libraries and starts with the reserved word uses. It should be the first among all other descriptions. The names of modules should be separated from each other by commas.
You can place a label on any code-code operator whose name should be mentioned in the corresponding section of the description.
Premature description of constants allows further in the code to write their names instead of numerical or letter values.
In the section describing the variables used, you should specify all the types that will be used: "var c, a, r: integer; k, l, m: char; h1, h2: boolean;".
Do not forget that "Pascal" is a programming language that requires a mandatory preliminary description of all the components involved in the program.
The code should end with a period.
Sample Programs
"Pascal" is an elementary language, and after studying the above information, you can proceed directly to writing the code.
Let's make the application display the phrase "It is my first program!"
Examples of programs on "Pascal" are very important to understand, so try to do it right now.
Begin
Writeln (It is my first program! ');
End.
That's so simple!
Look at the more complex code by which you can find the roots of the quadratic equation. Pay attention to the principle of forming computational expressions.
We hope that the examples of the Pascal programs were useful for you.
Similar articles
Trending Now