bug0152.pp 680 B

12345678910111213141516171819202122232425262728293031
  1. Program bug0152;
  2. {
  3. Shows wrong evaluation of loop boundaries. First end boundary must
  4. be calculated, only then Loop variable should be initialized.
  5. Change loop variable to J to see what should be the correct output.
  6. }
  7. PROCEDURE LGrow(VAR S : String;C:CHAR;Count:WORD);
  8. VAR I,J :WORD;
  9. BEGIN
  10. I:=ORD(S[0]); { Keeping length in local data eases optimalisations}
  11. IF I<Count THEN
  12. BEGIN
  13. Move(S[1],S[Count-I+1],I);
  14. FOR I:=1 TO Count-I DO
  15. S[I]:=C;
  16. S[0]:=CHR(Count);
  17. END;
  18. END;
  19. Var S : string;
  20. begin
  21. s:='abcedfghij';
  22. writeln ('s : ',s);
  23. lgrow (s,'1',17);
  24. writeln ('S : ',s);
  25. end.