tb0115.pp 822 B

12345678910111213141516171819202122232425262728293031323334
  1. { Old file: tbs0134.pp }
  2. { 'continue' keyword is bugsgy. OK 0.99.6 (FK) }
  3. {
  4. In this simple examply, the even loop is wrong. When continue; is called,
  5. it should go back to the top and check the loop conditions and exit when i =
  6. 4, but continue skips checking the loop conditions and does i=5 too, then it
  7. is odd, doesn't run the continue, and the loop terminates properly.
  8. }
  9. procedure demoloop( max:integer );
  10. var i : integer;
  11. begin
  12. i := 1;
  13. while (i <= max) do
  14. begin
  15. if (i mod 2 = 0) then
  16. begin
  17. writeln('Even ',i,' of ',max);
  18. inc(i);
  19. continue;
  20. end;
  21. writeln('Odd ',i,' of ',max);
  22. inc(i);
  23. end;
  24. end;
  25. begin
  26. writeln('Odd loop (continue is *not* last call):');
  27. demoloop(3);
  28. writeln('Even loop (continue is last call):');
  29. demoloop(4);
  30. end.