HP Pascal/iX Reference Manual (31502-90022)

6: 13
Example
WHILE index <= limit DO
BEGIN
writeln (real_array[index]);
index := index + 1;
END;
.
.
WHILE NOT eof (f) DO
BEGIN
read (f, ch);
writeln (ch);
END;
WITH .. DO
A WITH statement allows reference to
record fields
by field name alone.
A WITH statement consists of the reserved word WITH, one or more record
designators, the reserved word DO, and a statement. A record designator
may be a record identifier, a function call that returns a record, or a
selected record component.
The statement after DO may be a compound statement. In this statement,
reference to a record field contained in one of the designated records
can be made without mention of the record to which it belongs. The
appearance of a function reference as a record designator is an
invocation of the function. Note that a new value may not be assigned to
a field of a record constant or a field of a record returned by a
function.
When the program executes a WITH statement, the following occurs:
1. References to the record designators are evaluated.
2. The statement after the DO statement is executed.
The following statements are equivalent:
WITH rec DO BEGIN
BEGIN rec.field1 := e1;
field1 := e1; writeln(rec.field1
writeln(field1 * field2); * rec.field2);
END; END;
Because the program evaluates a reference to a record designator once and
only once before it executes the statement, the following statement
sequences are equivalent:
f designates a field in the example above.
i := 1;
WITH a[i] DO
BEGIN
writeln(f);
i:=2;
writeln(f)
END;
writeln(a[1].f);
writeln(a[1].f); { NOT writeln(a[2].f) }
That is, within the WITH statement, the implied value of a[i] is not
affected by the change to i.
Records with identical field names may appear in the same WITH statement.
The following interpretation resolves any ambiguity.