The Repetition Prog ram Structure 93
loop terminates. The for-loop is similar to the while-loop in that the condition
is evaluated before carrying out the operations in the repeat loop.
The following listing in pseudo-code uses a for-loo p for the repe titio n pa rt
of the summation pr oblem. Variable j is the counter variable, which is auto-
matically incremented and is used to control the number of times the state-
ments in a block is to be performed.
for j = 1 to num do
set sum = sum + 12.5
set y = x * 2.5
endfor
display "Value of sum: ", sum
display "Value of y: ", y
In Python, the simple use of the for statement uses function range. The
first, last, and the increment values of the loop counter are specified. The last
value specified is not really included ...