tb0131.pp 896 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. { Old file: tbs0152.pp }
  2. { End value of loop variable must be calculated before loop variable is initialized. OK 0.99.11 (PM) }
  3. Program tbs0152;
  4. {
  5. Shows wrong evaluation of loop boundaries. First end boundary must
  6. be calculated, only then Loop variable should be initialized.
  7. Change loop variable to J to see what should be the correct output.
  8. }
  9. PROCEDURE LGrow(VAR S : String;C:CHAR;Count:WORD);
  10. VAR I,J :WORD;
  11. BEGIN
  12. I:=ORD(S[0]); { Keeping length in local data eases optimalisations}
  13. IF I<Count THEN
  14. BEGIN
  15. Move(S[1],S[Count-I+1],I);
  16. FOR I:=1 TO Count-I DO
  17. S[I]:=C;
  18. S[0]:=CHR(Count);
  19. END;
  20. END;
  21. Var S : string;
  22. begin
  23. s:='abcedfghij';
  24. writeln ('s : ',s);
  25. lgrow (s,'1',17);
  26. writeln ('S : ',s);
  27. if s<>'1111111abcedfghij' then
  28. begin
  29. writeln('tbs0152 fails');
  30. halt(1);
  31. end;
  32. end.