What does writeln mean in pascal. Data input statements ReadLn and Read

Read And ReadLn read information from the standard input device. In console applications, this device can be, for example, a keyboard (more precisely, data entered from the keyboard); in graphical applications, it can be a file on disk.

That is, these procedures are “antipodes” - they perform actions opposite to them.

The Read and ReadLn procedures perform similar actions. The main difference between them is the following: the ReadLn procedure, after completing the input, performs a line feed (and in the case of files, reads the file line by line). And the Read procedure reads data in a row - without a line feed.

NOTE:

I don’t remember this in Turbo Pascal (maybe I just forgot), but keyboard input can only be performed using the ReadLn procedure, and for some reason the Read procedure does not work.

Syntax for console output:

procedure Read(Args: Arguments);

Syntax for output to file:

procedure Read( var F:Text; Args: Arguments);

Arguments ( Arguments) may be different. If several variables are used, they are listed separated by commas. For example:

Var x, y: integer; z:real; str:string; begin WriteLn("Enter three space-separated integers:"); ReadLn(x, y, z); WriteLn("You entered: ", x, ", ", y, ", ", z:0:2);

ReadLn(str);

WriteLn(str + str);
ReadLn; end.

As already mentioned, when entered from the console, these variables can be of different types. But, unlike the Write/WriteLn procedures, it is not allowed to use (and this is logical))).

IMPORTANT! When entering data, be aware that if the value entered by the user is of a different type than the type of the variable into which this value is entered, a run-time error will occur. If, for example, in the example above, the user enters a real value (such as 3.14) as the first number, the program will crash because the variable x is of integer type. When reading from a file, you can work with both typed and text files. When entering data, be aware that if the value entered by the user is of a different type than the type of the variable into which this value is entered, a run-time error will occur. If, for example, in the example above, the user enters a real value (such as 3.14) as the first number, the program will crash because the variable x is of integer type. If When entering data, be aware that if the value entered by the user is of a different type than the type of the variable into which this value is entered, a run-time error will occur. If, for example, in the example above, the user enters a real value (such as 3.14) as the first number, the program will crash because the variable x is of integer type. F

(see syntax) is a typed file, then variables passed as parameters (Args) must have the same type as specified for the file When entering data, be aware that if the value entered by the user is of a different type than the type of the variable into which this value is entered, a run-time error will occur. If, for example, in the example above, the user enters a real value (such as 3.14) as the first number, the program will crash because the variable x is of integer type.. Untyped files are not allowed. If the parameter is not specified, it is assumed that reading is performed from the standard input device. If the file

If, when reading a file, there is no data available for reading, then an empty value is returned to the variable F (0 for , an empty string for strings).

When using the ReadLn procedure, that is, when reading data line by line, the end of the line is indicated by a certain sequence of characters (which ones exactly depend on the operating system, for DOS/Windows these are two characters - #10 and #13).

The end-of-line marker is not part of the line read and is ignored.

If an error occurs during the Read/ReadLn procedure, a run-time error is generated. This behavior is not always acceptable (for example, while reading a file). Therefore, in some cases, error generation is disabled. This can be done using .

NOTE:

In various debugging and training programs, the ReadLn procedure is often used to prevent the console application from automatically closing after execution. To do this, at the end of the program simply write (as in the example above):

That is, just the name of the procedure without parameters. In this case, the program will wait for the ENTER key to be pressed. Therefore, the program will not end until the ENTER key is pressed, allowing you to see the result of the program. Of course, in the operating system

The Readln procedure is used for more than just screen delay. Its main task is to enter data from the keyboard. In this article we will learn how to enter numbers from the keyboard and then display them on the screen. To do this, we will need to get acquainted with the section for describing Var variables, as well as one of the data types used in Pascal.

Program number3; uses crt; var n:integer; begin clrscr; write('Enter a number from the keyboard:'); readln(n); writeln('You entered a number',n); readlnend.

In line No. 3 we write the service word Var. It is used to declare variables. Variables are different values, numbers or words that can change during program execution. When we enter numbers or letters from the keyboard, they are written to variables. After the word Var, we indicate the variable identifier separated by a space (that is, its name, which we come up with ourselves). Variables are not function words; the programmer sets them himself. In this case, we have set one variable “n” and in the future we will only use this variable. After writing a variable, the data type is indicated by a colon. There are several data types. One of them is Integer. It tells the program that our variable "n" can only be an integer ranging from -32768 to 32767. The use of different data types depends on the specific needs of the programmer when writing the program. The most important thing at this stage is to understand that if you are going to use a number in your program, then you need to specify a variable for it (in our case, “n”) and a data type (in our case, Integer).

In line No. 7 we write the operator for entering data from the Readln keyboard. This statement calls the built-in data entry procedure and at this stage the program stops and begins to wait for data input. We have already used this operator to delay the screen. In this program, after the Readln operator, our variable “n” is indicated in parentheses. The number that we enter from the keyboard will be written to this variable. Accordingly, this number must correspond to the parameters of the variable, i.e. must be an integer in the range -32768 to 32767. After the program reaches the 7th line, it will display the message “Enter a number from the keyboard: ” and wait. At this stage we must enter some number and press Enter.

Line No. 8. Here we write the Writeln screen output statement. It will display the message “You have entered a number”, and will also display the value of our variable “n” (i.e. the value that we enter from the keyboard). Please note that in line No. 8 we put a comma before the variable “n”, and the variable itself is not enclosed in apostrophes.

Now let's type the program in Pascal.

Launch (Ctrl+F9). Type a number, for example, 5 and press Enter.

Read (procedure)

For typed files, reads the file component into a variable.
- For text files, reads one or more values
into one or more variables

Announcement

Typed files

Procedure Read(F , V1 [, V2,...,Vn ]);

Text files

Procedure Read([ Var F: Text; ] V1 [, V2,...,Vn ]);

Mode

Windows, Real, Protected

Notes

For string variables:

Read reads all characters up to (but not including) the next end-of-line marker or until Eof(F) will become True. Read doesn't move to the next line after reading. If the resulting string is longer than the maximum length of the string variable, it is truncated. After the first Read, each subsequent Read call will see an end-of-line marker and return a zero-length string.

Use multiple ReadLn calls to read multiple string values.

When the option is enabled Extended Syntax, the Read procedure can read null-terminated strings into null-based character arrays.

For variables of type Integer or Real:

Read will skip any spaces, tabs, or end-of-line markers preceding a numeric line. If the numeric string does not follow the expected format, an I/O error occurs, otherwise the variable is assigned the resulting value. The next Read will begin with the space, tab, or end-of-line marker that terminated the number line.

see also

Example

uses Crt, Dos;

var
F:Text;
Ch:Char;

begin
(Getting the file name from the command line)
Assign(F, ParamStr(1));
Reset(F);
while not EOF (F) do
begin
Read(F, Ch);
Write(Ch); (Display the contents of the file on the screen)
end ;
end.

I think many people will be interested in this)))

read and readln instructions

The read instruction is intended for entering variable values ​​(initial data) from the keyboard. In general, the instructions look like this:

read (Variable1, Variable2, ... VariableN)

where variables is the name of the variable whose value must be entered from the keyboard during program execution.

Here are examples of writing a read instruction:

read(a); read(Cena,Kol);

When the read statement is executed, the following happens:

1. The program pauses its work and waits until the required data is typed on the keyboard and a key is pressed .

2 http://tissot.ua/ buy wristwatch watches buy Kyiv. . After pressing the key the entered value is assigned to the variable whose name is specified in the statement.

For example, as a result of executing the instruction

read(Temperat);

and entering line 21 from the keyboard, the value of the Temperat variable will be the number 21.

A single read statement can retrieve the values ​​of multiple variables. In this case, the entered numbers must be typed on one line and separated by spaces. For example, if the type of variables a, b and c is real, then as a result of executing the instruction read(a,b,c); and enter the line from the keyboard:

4.5 23 0.17

the variables will have the following values:

a = 4.5; b = 23.0; c = 0.17.

If there are more numbers typed in a line than the variables specified in the read instruction, then the remaining part of the line will be processed by the following read instruction http://crystal.lviv.ua crystal crystal. . https://mainvisa.com.ua photo invitation to Ukraine for foreign citizens. . For example, as a result of executing instructions

read(A,B);

read(C);

10 25 18

and keyboard input string

the variables will receive the following values: A = 10, B = 25. Read instruction (C); will assign the value 18 to variable c.

The readln instruction differs from the read instruction in that after selecting the next number from the string entered from the keyboard and assigning it to the last variable from the list of the readin instruction, the remainder of the line is lost, and the next read or readin instruction will require new input.

For example, as a result of executing the instruction

readin(A,B);

10 25 18

read(C);

and entering the line from the keyboard

the variables will receive the following values: A = 10, B = 25. After which the program will wait for a new number to be entered in order to assign it to variable c.

Each read or readin instruction should be preceded by a write instruction to tell the user what data the program expects from him. For example, a fragment of a program for calculating the cost of a purchase may look like:

writeln("Enter initial data.");

Write("Item price:");

Readln(Cena);

write("Quantity in batch:");

Readln(Kol);

write("Discount:");

You are in the Pascal programming materials section. Before we start programming, we need to clarify some concepts that we will need in the beginning. After all, you can’t just program like that. We cannot write the program in words - the computer does not understand anything other than zeros and ones. For this purpose, special symbolism was created in Pascal - the Pascal language, a set of reserved words that cannot be used anywhere else in your programs except for their intended purpose. Let's list the basic concepts that we will 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, does not need to 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 entry of the program.

✎ 2) integer – in English means “integer” (or simply “integer”) and in Pascal is used to denote 32-bit (8 bytes) signed integers from the range [-2147483648, 2147483647] . We will look into what these large numbers mean later.

✎ 3) real – from English “real”, “real”, “real”, “real”. In the Pascal language, this term denotes real numbers in 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, the 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 quantity that cannot change. It is written like this:


This entry must be taken as it is written: the number N is 12, S is 5, “pi” is 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 forward slashes), followed by text - this is how comments are written in Pascal, and the program does not perceive them. Everything that begins with a double slash and until the end of the line is a comment, which is written to explain the program and is always highlighted in a different color (in PascalABC.Net it is green; Turbo Pascal does not use this type of comment). There is another type of comment - this (text enclosed in curly brackets, just like here, also highlighted in green). This type of comment can be valid for several lines in a row - from the beginning of the bracket to its closing, and the compiler does not perceive everything that is in the middle of such a construction as code and simply skips it.

In reality the recording format const a little more complicated. 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 figures: 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 indicated, and then a value is assigned. But the previous entry is also correct, since the Pascal compiler is configured so that it automatically determines the type of a 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. The variables N, m (integer) and Q, r, t (real) in the program can change values ​​within the limits of integer and real, respectively. One more note: the description of variables always comes after the description of constants (constants) - the const construction comes first, and then var.

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

✎ 7) end – in English. “end”, and in Pascal it means the same thing (end of the program). After the last word end there is always a period. We have emphasized 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 on that later. So the main program will look like this:

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

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

✎ 8) write – in English means “to write”. This operator displays the text placed in it, which is why it is called the output operator. The text placed inside it is highlighted in blue and written like this:

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

A message inside 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 in the case when you need to show a hint, explanation, comment, etc. And if you also need to display a numerical value, say, S = 50 sq. m, then the format is used:

Write(, S);

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

The area is equal to: S = 50

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

Write( "The area is equal to: S = ", S, " sq.m" );

After executing the last output statement, we get the following 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 be moved to the next line.

✎ 10) read – translated from English means “to read”, so read is called the read or data input operator. It is 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 =” (space at the beginning); Next we see the readln(Year) operator, which means it is necessary to enter the age Year (number 32); finally, we display the messages “My age”, “32” and “years. " one by one. You need to watch the spaces carefully. As a result of executing this code, we will receive the message:

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

✎ 11) readln – the same as read, only with a new line. Indeed, in the above example, after introducing the number Year, we only write in the next line: “ My age is 32 years old».

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