for
SYNTAX:
for iteration_variable := initial_value to final_value do statement
or
for iteration_variable := initial_value downto final_value do statement
DESCRIPTION:
"for" is reserved word in all Pascal standards. It is used for introducing iterative loops during the execution. At the start of the loop the control variable set to the initial value then incremented by 1 after each execution step of the body of the "do" statement. The control variable should be an integer type. When the value of the control variable equals to the final value the execution continues at the next statement after the body of the "do". If the initial value and the final value are equal the loop executed ones. If the initial value higher than the final value the body of the "do" statement not executed.
In the second form of the command the control variable decremented by 1 in each cycle. The relation of the initial and final values are reversed accordingly.
The body of the "do" statement can contain other "for" cycles resulting nested loops. It is an error to set the value of the loop-control variable inside the loop. The code that violate that rule will compile and run - if there are no other errors - but the result will be unpredictable.
After the execution of the loop the value of the control variable is undefined. A proper code should not relay on that value.
STANDARDS: All
EXAMPLE:
var i,j,k:integer; vec:array[1..10] of integer; cube:array[1..10.1..10.1..10] of real; ... for i:= 1 to 10 do begin write('element [',i,']:? '); { prompt for the next value } readln(vec[i]); { read it } end; ....
for i:= 1 to 10 do { load data from "infile" } for j:= 1 to 10 do begin for k:= 1 to 10 do read(infile,cube[i,j,k]); readln(infile); { next line } end; close(infile);
SEE ALSO: do, while, repeat
________________________________
Comment this please.
miklos