[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
var Signals the Start of a Set of Variable Declarations
var
<vnames> : <oldtype>;
<vnames> : <low>..<high>;
<vnames> : (<item1>,<item2>,...,<itemN>);
<vnames> : <filetype>;
<vnames> : <settype>;
<vnames> : <arraytype>
<vnames> : <recordtype>;
The VAR section is used to declare variables. These variables can be
any of the following data types: existing data types, subranges of
existing ordinal data types, enumerated data types, or array-, record-
, or set-based data types.
<vnames> One or more variable names, separated by commas.
<oldtype> Any previously declared or predeclared data type.
<low>,<high> Any two values of the same ordinal (Integer, Char,
Boolean, enumerated) type. <low> must be less than
or equal to <high>.
<item1>, etc. A list of standard identifiers, naming the different
values of an enumerated data type. All the
identifiers must be unique and not previously
declared.
<filetype> Any legal FILE declaration.
<settype> Any legal SET declaration.
<arraytype> Any legal ARRAY declaration.
<recordtype> Any legal RECORD declaration.
In Standard Pascal, you can have at most one VAR section per program
or subprogram (procedure, function), and it must appear after the TYPE
section and before any subprograms. Turbo Pascal allows you to have
multiple VAR sections per program or subprogram and requires only that
they appear before (and outside of) the main body of that program or
subprogram.
-------------------------------- Example ---------------------------------
var
I,J : Integer;
X,Y : Real;
Ch : Char;
Flag : Boolean;
Name : NameStr; { must be previously declared }
Day : Days; { ditto }
OKSet : CharSet; { ditto }
List : NumList; { ditto }
Who : Student; { ditto }
You can define types in the var section; however, the type has no name
and therefore cannot be used for other variables or for parameters.
var
Name : string[20];
Day : (Sun,Mon,Tues,Wed,Thur,Fri,Sat);
OKSet : set of Char;
List : array[1..1000] of Integer;
Who : record
Last,First : string [40];
SSN : string [30];
GPA : Real
end;
See Also:
file
set
array
record
type
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson