Richard Sharman wrote:
Frank Heckenbach writes: | Norberto Alfredo Bensa wrote: | The problem is the following: You use a for loop counter (h) after | the loop, and in Pascal this is undefined (this might be one of the | most despised features of Pascal, but it has its reasons). | Therefore, it's quite possible that one compiler does what you want | and another compiler (or another version of the same compiler) | doesn't. |
Isn't it also wrong to attempt to modify a FOR loop index variable inside the body for the FOR statement?
Yes, it is. I'd missed that one. (Using a while loop will avoid this problem as well, of course.)
for h := 1 to j-1 do if 2*p[h]>i then h := j { <------- } else if i mod p[h]= 0 then break;
I thought this was not allowed in Pascal, but I see gpc accepts it.
I agree, GPC should check this more strictly (at least give a warning).
Frank