Pascal: variable i : 1..10;

Viewed 188

I have this part of code. My question is what the variable i: 1..10; is and what am I declaring. Thanks

type
Str25 = String[25];
TBookRec = Record
  Title, Author, ISBN : Str25;
  Price : Real;
End;

Var
BookRecArray : Array[1..10] of TBookRec;
tempBookRec : TBookRec;
bookRecFile : File of TBookRec;
i : 1..10;
1 Answers

When the variable I is declared like this:

var i : 1..10;

it means that variable i is an integer subrange which can take a value between 1 and 10 inclusive.

The code you show is frequently declared like this:

type
    Str25 = String[25];
    TBookRec = Record
        Title, Author, ISBN : Str25;
        Price : Real;
    End;

    TBookRecIndex = 1..10;

var
   BookRecArray : Array [TBookRecIndex] of TBookRec;
   TempBookRec  : TBookRec;
   BookRecFile  : File of TBookRec;
   I            : TBookRecIndex;
Related