Pascal programming language tutorial. Learning to Program from Scratch - A Step by Step Guide for Beginners

Today, many are interested in whether it is possible to learn to program from scratch.

We have all heard the stories that the people who are in this business have huge incomes, go to Bali every weekend and in the first months of their work were able to buy apartments for all their relatives.

In principle, this is not far from the truth, but For such results, experience and reputation are needed. And you need to start with the simplest. We will look at the steps that a person who knows nothing about writing programs needs to follow in order to travel to Bali and buy property in the future.

Content:

Step one. Training

Often, novice programmers fail to succeed for the simple reason that they initially failed to prioritize correctly.

They present this craft as something romantic, dynamic - just some kind of constant action.

In films, this process is shown completely different from what it really is.

Moreover, there is generally coding is not displayed, we are shown only the events that revolve around it.

Also in films they show that any person without knowledge, experience and even without gray matter in the brain can become a programmer. In this case, we can recall the film "Personnel".

So if you just got into the spirit of all kinds of films and want to start “coding” yourself, programming is clearly not for you.

Here's the truth about the craft in question - programming is:

  • hours, and sometimes days of monotonous work during which you can not relax, you must always be focused;
  • endless learning in pursuit of the latest trends in this area;
  • similar projects with customers who do not know what they want and how it should look like.

As for the latter, you must it is worth watching a video about seven red lines of different colors, one of which is in the form of a kitten. In principle, this is close to the truth, as customers often demand the impossible. It also happens that they order something, but the result constantly does not suit them.

https://youtu.be/nU0Fy5JXOtY

If you understand all this and are ready to plunge into the wonderful world of programming, then proceed to the next step.

Step two. Choice of first language

There are a huge number of programming languages. According to some estimates, their number has already reached several thousand.

In general, C is one of the simplest languages, which provides the basis for everything else. Moreover, its elements are used in many other systems and programs.

But it is interesting that in good educational institutions, as well as In the courses, students learn languages ​​in the following order:

1 Pascal.

2 C++.

3 PHP and everything related to web programming as well SQL(this is a system designed to work with databases through queries).

  1. Web(development of websites, online systems and everything connected with it) – html(although it cannot be called a full-fledged programming language), PHP, Perl, Python, Ruby, Java, Groovy, and ASP.NET technology.
  2. User software(all kinds of programs like directories, browsers, instant messengers, etc.) - Delphi, C, C++, C#.
  3. User software for mobile devices– Java, Objective-C.
  4. Machine development(work with microprocessors and other devices, robotics design) - Assembler, modifications C.

Someone can also add the so-called 1C programming to this list. Do not trust laymen and ignorant people! This is not programming at all.

When you get to know the basics of the work in question, you will understand why this can be said.

Choose what you like the most.

Advice: Make your choice now! You must know exactly in which direction you will develop and what to study in the future.

Most experts also are advised to start their studies with Pascal. This option will allow

You will write the simplest programs and have a general idea of ​​the craft in question as a whole.

We can say that Pascal is a kind of bridge. A person who just knows mathematics well can go through it into the world of programming.

Attention! Whatever company you get a job after training, you will be retrained for yourself. Therefore, you should simply understand the very principle of writing programs. And for this there is nothing better than Pascal.

Step three. Learning Compilers

For reference: Compiler- This is a technical solution designed to translate input commands into machine instructions, roughly speaking, into zeros and ones, that is, into such an interpretation on which the machine will understand what to do.

Actually, you will write all your programs and execute them in compilers.

If you decide to follow our advice and start with Pascal, then you should download Free Pascal. This compiler is absolutely free and distributed on the official website.

As you can see, it looks rather "old-fashioned", but programming begins with this. By the way, the C++ compiler looks pretty much the same.

It's called Turbo C++ (you can download it).

As for Pascal, there are also GNU Pascal, Turbo/Borland Pascal, TMT Pascal and Virtual Pascal. And for C++ you can use Borland C++, +, Dev C++, GCC and Eclipse.

But this, as we said above, is only the beginning. You can't stop there. Once you've made a choice about your direction, you can move on to more complex compilers.

Here is a list of the most popular compilers today depending on the areas of activity:

    ConcerningDelphi, then the compiler is called there. There is also Embarcadero Delphi and some other modifications. Delphi 7 can be downloaded from many sites, for example,. If you chose C, C++ or C#, then you need Microsoft Visual Studio. You can download it directly on the official website of the manufacturer.

    If we talk aboutAssembler and other languages ​​that are practiced in robotics, then here you immediately need to download MASM if you are working on Windows. In general, depending on the field of activity you have chosen and the company for which you get a job, compilers can be very different. Some firms write their own code processing solutions. Therefore, if you have chosen robotics, it is better to study the relevant books and do everything as they say. We'll talk about this later.

There are also many online compilers. They are useful in that they serve many programming languages ​​and do not require installation - very convenient!

Here are the most popular ones:

This is a unique service that allows you to create several virtual computers and do whatever you want on them, including compiling ciphers.

The virtual machines will be running . On them, you can at least delete the system folder, install absolutely any program, and so on.

Now let's start writing your first cipher (code). You can do this even without books and long instructions.

Step four. First code

For the first code, we will use the first language and the first compiler that we advised you to choose above. These are Pascal and Free Pascal.

One of the easiest programs is written as follows:

1 Download Free Pascal from the link above and run it on your computer.

2 Enter the following: "program [name];". That is, if you want the program to be called "hello", you must enter "program hello;".

3 Enter the instruction "begin". This means that the code that will later need to be executed has begun.

4 We use one of the most common constructions in Pascal "writeln('[some text]');". It just displays text on the screen. Which is contained in brackets and quotes. We will introduce a combination "Hello, world!". Usually, they start their way into the big world of software development with this. So the next line will look like "writeln('Hello, world!');".

5 To complete the executable cipher, enter "end."(required with a dot at the end).

6 Now press the button F9 to run what you wrote. You will see the words appear on the screen "Hello, world!". This is what was required!

To get you started with other languages, books usually also provide instructions on how to write "Hello, world!" , that is, an instruction that simply displays such simple text on the screen.

So, you have mastered your first cipher! A start. Now move on to intensive training.

Step five. Take an online training

The advantage of online lessons is that you see everything clearly, from start to finish.

Therefore, it is better for beginners to start their journey with online trainings. Here the best courses in Russian:

If you chose Python, check out McGrath's Python Programming for Beginners.

Step seven. Stay up to date

When you have sufficiently studied the material in the chosen direction and already have some experience, you need to constantly monitor the development trends of the software market.

Here's what it's about:

All this is necessary so that you can rebuild on time.

Let's say you decide to do a certain kind of programming, you've learned the technology, and you're ready to go to work to submit your resume.

Your data is considered, but they say that the company needs a specialist of a different profile.

So that you have as few such situations as possible, you should always know which areas of development are currently the most popular.

Important! Study both global trends and the situation in your city where you are going to work. If you want to be a freelancer, study orders on various exchanges and forums.

All this will allow you to develop and work in the right direction without wasting precious time.

This is very important in our time, as programming trends change not only in a few months, but in a few days!

If you learned some programming techniques two or three years ago, Now all this is definitely irrelevant.

Step eight. Find a teacher

It is best to find a personal mentor who will tell you what and how best to do in a particular case.

This option has many positive aspects, the main of which is the presence of a personal approach to you personally.

In addition, if problems arise, the teacher will help you solve them. BUT You can find a mentor in the following ways:

1 Enter the university. Yes, training programs in post-Soviet countries can be quite outdated, but you can definitely comprehend the basics, the very principle of programming, some basis of everything

2 Various courses. There are a huge number of courses where people gather in some office and the teacher, just like in a university, explains this or that concept. Usually such courses are very intensive, and students quickly learn the necessary information.

Of course, the services of a teacher will cost money, but the study will be very productive, and you will be able to learn a lot of necessary information.

Step nine. Analyze other people's work

This is a very interesting method that allows you to develop very quickly. The fact is that it is very difficult to understand someone else's code, only a few even professional programmers are capable of this.

If you do this at the very beginning of your activity, for sure, you will be able to reap excellent results in the future.

Moreover, it will allow you to become a project manager in the future, as you will have the ability to correct the work of other people.

More specifically, you need to do the following:

  • think about how you could optimize the cipher, that is, reduce the listing;
  • look for errors and shortcomings without a compiler and with it;
  • Work and, accordingly, earnings in your pocket! And if it doesn't, keep practicing. At least you know what tasks you need to do to get hired.

    In any case, give it enough time and then you will succeed!

Pascal is a high level programming language. But he is very outdated morally. Because the world does not stand still. And other languages, such as: C# and Java, have a greater demand and efficiency of writing code, unlike Pascal. It is studied not so much for application as for teaching in educational institutions. Because it is easy to understand and cannot harm the system from incorrect user code. I have provided you with a list of lessons that you can follow to learn it thoroughly.

To write programs in Pascal, you must enter the programming environment. If you do not have this program, then you can download it on any site

If you have it, then proceed to the learning process.

After completing all the lessons, you will get examples of problem solving, an idea of ​​writing programs in general, and also learn a programming language TurboPascal.

Developed by: Professor NTU "KhPI" Domnin Felix Arkadyevich

The PascalABC programming environment is used as an initial training in programming in the Pascal programming language. The environment contains a powerful help system and a built-in task book with auto-checked tasks.

In the free mini-version of the problem book, 270 tasks are available in all main sections. This is quite enough for independent development of the initial level of programming. Download version 3.0 here . Currently this version is no longer supported and the developers are working on PascalABC.Net . So let's start learning pascal abc.

Appearance of the interface of the PascalABC program

The programming environment window looks standard. It has a menu bar (1), below is a quick access toolbar (2). Next is the working area of ​​the code editor.


Appearance of the program interface

Labels of open files with program texts are displayed at the top (3). Simultaneous work with several texts greatly simplifies the creation of programs. You can copy and move sections of code from one file to another (4).

In the program execution mode, you can see the data entry and result output area (5).

Working with PascalABC

After typing the text of the program, you must save it and set a name. To do this, you can use the command File-Save As or the corresponding button on the toolbar.

Give a name different from the default. This will make it easier for you to find the right code in the future.

launch

Now you can run the program to check its operation. Run command Program -Run or the green triangle button on the toolbar. The code is compiled before running. If there are errors in the code, a red line will appear with a description of the error.


Errors in the program

The cursor will indicate the location of the probable error, but this does not always match its description. For example, in the screenshot above, the cursor points to the Y variable, but the error is contained in the line above. There is a missing semicolon character, which must be at the end of each command line. After fixing the error, run the program again.

Stop

The program stops when it ends. But there are cases when the program needs to be stopped forcibly. To do this, there is the "Stop" button on the toolbar or the command Program - End.

Setting up a text editor

By default, the code editor is set to a minimum font size. If you experience discomfort when typing, then go to the menu Service - Editor Settings. Set the desired font size.


Setting up the Pascal ABC editor

Working with an electronic task book

Go to the menu Tools - Create program template. You will see the following window (see below)

Here you need to write the name of the task group. We look at the list and enter the desired group exactly as it is written in the window list. After specifying the name of the task group, the tooltip will change.

The number of jobs available in that group will now be listed, or specific job numbers will be listed. You add a number to the group name without a space. We press the button. A tab will open with the selected task. The new file will contain the automatically generated code. It cannot be deleted.

Now, to view the text of the task, click on the program launch button.

Look at the window above. It is divided into three parts. In the first part, the condition of the problem for which you need to write code is given. In the second part, numbers are indicated in yellow. This is the initial data generated by the problem book. They will be read. The third part displays the result that will be obtained when executing your program. Now close the window and add the code.

We launch for execution. If there are no errors, then we get a window.

It is necessary to carry out several repeated launches of the program in order to pass all the tests. And only after passing all the tests, the task will receive the status "Task completed!" Now you can move on to the next task.

Usually, the study of any programming language begins with the program Hello, world! But we will deal with this a little later, because now I want to tell you about the values ​​​​and data types in Pascal.

Types of quantities

Usually, the study of any programming language begins with the program Hello, world! But we will deal with this a little later, because now I want to tell you about the values ​​​​and data types in Pascal. What is a value? A value is a separate information object stored in the computer's memory. There are two classifications of quantities. We will consider each separately.


We will talk about them in more detail in later lessons.

In turn, the numerical is divided into two types.


I immediately give the designation of this type in Pascal

Symbols are also divided into two types.

The second classification of quantities.
Constant - the value is unchanged. Variable - the value can change during the execution of the program. Variables are denoted by symbolic names, which are called identifiers. How to assign a value to a variable? With the assignment command! Assignment command in Pascal: < переменная >:= < выражение >

First Pascal program

Program structure in Pascal

header

program< имя переменной >;

Declaring Variables and Constants

const<Символическое имя> = <выражение>;
var<Однотипные переменные> : <тип>;

Operator section

Begin
<оператор 1>;
<оператор 2>;

end.

Input and output in Pascal

You, for sure, have a question: “How to enter the values ​​of variables from the keyboard?”, And also: “How to display the result obtained on the screen?”. There are four special operators for this:

For input:

  • read(Variable)
  • readln(Variable)

And for output:

  • write(Text in ")
  • writeln(Text in ")

“What is the difference between read and readln, write and writeln?”: you will be puzzled again. The answer is simple. If you add "ln" (which stands for Line), then the cursor moves to the next line.

Hello World in Pascal

You are now ready to write your first program.

Program Hello_World; (curly quotes allow you to insert a comment to the code) Begin Write("Hello, World!"); end.

Well, everything is clear here. To diversify the solution, I propose to solve several problems of this type.

Task 1. You want to ask for a username and then print "Hi,<имя>!» To solve this problem, we need a string data type - string.

Program Hello_boy_girl; (curly quotes allow you to insert a comment to the code) var name: string; (declaring name is a new variable) Begin Write("Enter your name: "); (since we are using write, the cursor will flash after the colon) Read(name); (Read whatever the user has entered) Write("Hi,", name, "!"); (Please note! The variable is separated from the quotes by COMMA End. !}

Task 2.It is required to find out how old the user is, and then display "You<возраст>years". Obviously, to solve this problem, we need an integer data type - Integer.

Program How_old_are_you; var years: integer; (declaring years is a new variable) Begin Writeln("How old are you?"); (because we're using writeln, the caret will blink below the label) Read(years); (We read everything that the user entered) Write("You are ", years," years."); end.

Well that's all! Everything I wanted to tell you in today's lesson. You have learned what a value is in Pascal and learned the basic types. They also learned how to create simple linear programs. We will talk in more detail about types in PascalABC.Net in the next lessons. By the way, about PascalABC.Net. It is clear that writing programs on pieces of paper is useless, and you should train on a computer. Download the latest version for Windows from this link.
Here's what the program's interface looks like when it starts up.


P.S. Let's highlight two features of Pascal:

  1. Pascal is NOT case sensitive, that is, program, and Program, and PrOgRaM are no different for it. And therefore, from the very beginning, get used to writing in lower case, so that when you switch to another programming language, you will not experience any problems with this;
  2. The name of the program in Pascal does not play any role, it does not carry any useful functions. If you want, you can just not write IT!

P.P.S. There are three most popular operating systems in the world: Linux, Mac OS and Windows. What if you don't have Windows? Which compiler to choose then? We will talk about this in lesson number N.

You are in the section of materials on programming in Pascal. Before we start programming, we need to clarify some concepts that we will need at the beginning. You can't just program like that. We cannot write the program in words - the computer, apart from zeros and ones, does not understand anything else. To do this, Pascal created special symbols - the Pascal language, a set of reserved words that cannot be used in their programs anywhere else, except for their intended purpose. We list the basic concepts that we need at the beginning:

✎ 1) program - in English “program”, written at the very beginning of the code, followed by the name of the program in Latin and a semicolon. For example: program Summa; − a program called Summa. But this part of the code, called the program header, may not be written - it is present only for clarity and shows what problem this program solves. Here we used the word "code" - this is the name of the text record of the program.

✎ 2) integer - in English it means "integer" (or simply "integer") and in Pascal it is used to denote 32-bit (8 bytes) signed integers from the range [-2147483648, 2147483647] . What these large numbers mean, we will analyze later.

✎ 3) real - from English “real”, “real”, “real”, “real”. In Pascal, this term refers to real numbers from the range [-1.8∙10 308 , 1.8∙10 308 ] . These are very large numbers, but 15 - 16 significant digits are displayed. By the way, integer and real data types in the PascalABC.Net programming environment are always automatically highlighted in blue.

✎ 4) const - analogue of English. "constant", meaning "constant", "constant". In Pascal, this is a value that cannot be changed. It is written like this:


This entry should be taken as it is written: the number N is equal to 12, S is equal to 5, "pi" is equal to 3.14 (as in mathematics, only a dot is used instead of a comma in Pascal). In the last line, we used a double slash (two slashes), followed by text - this is how comments are written in Pascal, and the program does not perceive them. Everything starting with a double slash and up to the end of the line is a comment that is written to explain the program and is always highlighted in a different color (in PascalABC.Net it is green, in Turbo Pascal this type of comment is not used). There is another type of comment - this (text enclosed in curly brackets, just like here, also highlighted in green) . This type of comment can act for several lines in a row - from the beginning of the bracket to its closing, and everything that is in the middle of such a construction, the compiler does not perceive as code and simply skips it.

In fact, the recording format const a little more difficult. According to the rules, we had to write:

1 2 3 4 const N: type integer;

Description:

")" onmouseout="toolTip()">integer
= 12 ; //number N - integer type S: type integer;

Description:
Represents a 32-bit signed integer.

Value range: -2 147 483 648 .. 2 147 483 647")" onmouseout="toolTip()">integer
= 5 ; //number S - integer type pi: type real;

Description:
Represents a double precision floating point number.

Size: 8 bytes
Number of significant digits: 15 - 16
Value range: -1.8∙10 308 .. 1.8∙10 308
")" onmouseout="toolTip()">real
= 3.14 ; //number "pi" - real

After declaring each value, its type is specified, and then a value is assigned. But the previous entry is also correct, because the Pascal compiler is configured to automatically determine the type of the constant. But this cannot be said about the next type of numbers - variables.

✎ 5) var - comes from English. “variable” (“variable”, or “changeable”), which in Pascal means a value that can change its value during the program. It is written like this:


As can be seen from the entry, there is no “=” sign here - variables of the same type are recalculated (separated by commas) and only the type is indicated after the colon. Variables N, m (integer) and Q, r, t (real) in the program can change values ​​within integer and real respectively. One more note: the description of variables always comes after the description of constants (constant) - first comes the construction const , and then var .

✎ 6) begin - translated from English means “begin” and Pascal means the beginning of the main program in which commands (operators) are written. After the word begin semicolon is not included.

✎ 7) end - in English. "end", and in Pascal means the same (end of program). After the last word end there is always a dot. We highlighted the word "last" because the use of the construction begin-end perhaps in one more case: these are the so-called operator brackets, which are used to combine several operations under one operator. But more about that later. So the main program would look like this:

1 2 3 4 5 6 begin < оператор 1 > ; < оператор 2 > ; . . . . . . . < оператор N > ; end.

Here, the statements in the body of the program are different commands to the compiler.

✎ 8) write - in English means "to write." This statement displays the text placed in it, which is why it is called the output statement. The text placed in it is highlighted in blue and written like this:

Write( "this text is displayed on the screen");

The message in parentheses and quotes will be shown in the console window (you can't just put it in parentheses without quotes). After executing this statement, we will see on the screen:

this text is displayed on the screen

In this form, the write operator is used when it is necessary to show a hint, explanation, comment, etc. And from if it is also necessary to display a numerical value, say, S = 50 square meters. m, then the following format is used:

Write(, S);

As a result, we get the result on the screen:

The area value is: S = 50

And if you need to display units of measurement, you need to insert the text in quotation marks after S again:

Write( "The size of the area is: S = ", S, "sq.m" );

After executing the last output statement, we get the output on the screen:

The size of the area is: S = 50 sq.m

✎ 9) writeln - the same as write, but after execution, the cursor will move to the next line.

✎ 10) read - translated from English means "read", so read is called a readout operator, or data input. Written as read(N), which means that the value N must be entered, where N is any number, or text, or other type of variable. For example, if we need to enter the age of a person who is 32 years old, we can write it like this:


In the first line of this code, the program displays the question " What is your age?» and moves the cursor to the next line (ending ln); in the second line we print "Year =" (a space at the beginning); then we see the readln(Year) operator, which means the need to enter the Year age (number 32); finally, we display the messages “My age”, “32”, and “years. » in turn. You need to be careful about spaces. As a result of executing this code, we will receive a message:

What is your age?
Year = 32
My age is 32

✎ 11) readln - the same as read, only with a newline. Indeed, in the example above, after entering the number Year, we only write in the next line: “ My age is 32».

That's all for now. On the next page we will write our first program, and in Pascal programming these will be our

Loading...Loading...