Peter N Lewis wrote:
Anyway, I see that this is an example, at least in theory. However, I'd probably do it differently in practice. I think this is more efficient, since you don't need any comparisons, and in particular no extra code in the innermost loop which is the most time-critical. If you need the original start values afterwards, copy the array before the first loop, of course.
for a1 := start[1] to max[1] do begin for a2 := start[2] to max[2] do begin
This is much nicer code than my version. However I would still choose to make the loop control variables a[1], a[2], a[3], etc., so that when I take the checkpoint the checkpointing procedure could use a loop like
for n := 1 to depth do writeln (checkfile, a[n]);
But surely regardless of any of this, even if the compiler refuses to allow a[1] (or much worse a[i]) as an index, any for loop can easily be rewritten in to a while loop a1 := start[1]; while a1 < max[1] do begin ... Inc(a1); end;
(possibly adding a temporary for the maximum if appropriate).
Please don't strip attributions for quoted material.
You forget that there are, or were, many machines out there with peculiar looping constructs available. A for can usually be mapped into these if certain restrictions are applied. Thus the prohibition against modifying the for variable, which may not exist within the loop. The terminal condition may then have very little obvious connection with the actual code. Using this looping construct may have major efficiency effects.
One such machine is the HP3000. I suspect the various Burroughs are/were similar. It is a long time since I used these, so the details have become hazy.