Download Documentation for Pic Micro Pascal

Transcript
PIC MICRO PASCAL V1.6 - USER MANUAL
4.10 FOR iterator NEW! (V1.6.0)
This particular form of the FOR statement has been introduced in the latest versions of Delphi and in FPC.
It is implemented in PMP as "standard Pascal".
FOR <Variable> IN <Enumerable> DO <Block>
<Enumerable> may be:
–
An array variable,
–
A string variable or a string literal,
–
An enumerated type,
–
A simple type variable (BYTE, CHAR, SHORTINT, WORD, INTEGER, LONGWORD, LONGINT); this
is a PMP special behavior, not a standard Pascal one, see below.
<Variable> is any simple variable compatible with the <Enumerated> element type.
Unlike a classic FOR loop which may loop with index values, the iterator loops on all element values
contained in <Enumerable>: this element value will be written in <Variable>.
Both <Variable> and <Enumerable> are read-only during the loop.
➢
In the following pseudo-codes, <Temp> is a stealth variable that is generated by the compiler,
containing the index in <Enumerable>.
The iterator behavior will differ a bit according to the type of <Enumerable>:
•
For an ARRAY <Variable> will contain all values contained in the array, the loop is implemented as
an equivalent of:
<Temp> := low(<Enumerable>);
WHILE TRUE DO
BEGIN
<Variable> := <Enumerable>[<Temp>];
<Block>
IF <Temp> < high(<Enumerable>) THEN
INC(<Temp>)
ELSE
BREAK;
END;
•
For a STRING <Variable> will contain all characters of the string; if the string is empty, <Block> will
not be executed. The loop is implemented as an equivalent of:
<Temp> := 0;
WHILE TRUE DO
IF <Temp> = length(<Enumerable>) THEN
BREAK
ELSE
BEGIN
INC(<Temp>)
<Variable> := <Enumerable>[<Temp>];
<Block>
END;
Document revision: A
S TAT E M E N T S - F O R
ITERATOR
NEW! (V1.6.0)
Page 67/101