Last Updated:

Clrscr function in Pascal

Clrscr function in Pascal

Sometimes you just need to remove all the text from the screen and make the workplace completely clean. For users who do not know about the special team in Pascal, it will be difficult at the same time - each symbol to erase manually using the Backspace will be a long task. And therefore, over time, a person will still look for a means to pass the time for this activity. Just in this material and will talk about the function in the Pascal language called Clrscr.

Before you can start running Clrscr, you need to know the basic rules for writing identifiers. If you make any mistakes, then a person simply will not be able to execute the code. And therefore, it will be necessary to think for a long time why certain values are not accepted.

To write code simply and immediately when analyzing lines manually to indicate errors - you should pay attention to the following list:

  • The identifier begins with a letter, or underscore;
  • Contains only letters, numbers, or an underscore;
  • There must be a separator between the two identifiers;
  • The maximum length is 127 characters. All symbols are meaningful;
  • The identifier cannot repeat a reserved word.

If any of these conditions are violated, then it will simply be impossible to carry out the plan. Pascal will present an error, which, of course, prevents full execution, since this contradicts the data in the language database. It is recommended to first learn certain rules, and then only start recording programs that also use the Clrscr function to clean the screen.

Also, it must be borne in mind that for the work of such an addition in the code, you need to connect a special module. It is called "usesCrt". Everything is due to the fact that Clrscr is written in this. And without it, accordingly, the algorithm will not function. It is recommended to make sure that the usesCrt module is present before testing the written code, otherwise you can think for a long time about a possible error that an entry-level programmer may not immediately remember.

In addition to the above, it is necessary to highlight the distinctive feature of Pascal. It is not case sensitive, which is why it is possible to write programs without any problems. Capital, lowercase letters – it doesn't matter. Because of this, with a small "error" related to the size of the symbol, there will be nothing serious. And also, it is possible to write the name of your own project as you like - this again, no role will affect the performance. The main thing is the very correctness of the lines of code entered by the user.

The value of the cleaning screen in Pascal – what is it?


What does a program that uses the Clrscr function actually do? As you can guess from the introduction, it allows you to quickly erase all the text written by the user in the program. Or, everything that is entered with the help of commands set by a person is removed.

An interesting moment can touch the color of the window. It is known that a person can adjust its color using a special command – "TextBackground". Thus, it is possible to change, for example, white to black, blue and other colors. And as for cleaning the screen – all the text is erased and the window is filled with the same color that was set by the user.


As for the replacement of symbols itself - they are not deleted, but rather replaced with others. Instead, spaces appear, and having the same color as the set background. If it is white, then the replacement of the text will be with the same parameter. And this works with many different shades set by the programmer in the code.


Also, the program using Clrscr not only replaces all characters with spaces, but can also move the cursor to a certain position. As a rule, this is the upper left corner of the window, so that the user can work later in the same way as with the new window that was just opened. A trifle from the team, but some pleasant sensations from the sight of a cleaned window will be delivered to those who want to work cleanly.


Here are some examples of using Clrscr:

uses crt;
var i:byte;
for i:=1 to 10 do
writeln(‘Введи что-нибудь’);
writeln(‘Экран чист’);

Also, it is worth noting one more such:

uses Crt;
WriteLn(‘Нажмите любую клавишу…’);

And one more:

uses CRT;
x1,x2,: integer;
x: integer;
Write(‘Введите х1’);
Write(‘Введите х2’);
writeLn (‘Число равно x= ‘,x)

Reasons for cleaning the screen in Pascal – when is it done?


When is the screen cleaned? Here, the answer can be as detailed as possible. There can be many scenarios when you apply a complete cleanup of the entire window from the code. However, it is worth paying attention to the most frequent case. After all, it is because of his incident that it is possible to resort to the use of the Clrscr command.

When the user fills the window completely with code that is not needed at all later, it is worth getting rid of it. The easiest way to fix the problem with unnecessary code is as simple as possible - using the Clrscr command. Then a person will have a clean desktop, which provides an opportunity for convenient writing of his project.

Most often, a product written in Pascal is relevant in the case when the old code is present, and it is no longer needed. The thing is that when the previous program is executed, it leaves behind the results. And accumulating different data, it will soon become difficult to navigate in all the information displayed.

Therefore, it is necessary to highlight only the important part - the new code. Since doing this manually is very difficult, you should resort to Clrscr. And if everything is done correctly - like the examples above, the screen will clear and everything will look great.

Having learned about everything basically, a person will be able to use the command without any difficulty to clear the field for new codes. This will be a very useful addition to the work, sometimes even necessary. So, it is recommended to use it if necessary and not to spare time for writing, as later it will pay off with the successful functionality of the code.