program stops after reading procedure (delphi)

帅比萌擦擦* 提交于 2019-12-14 03:14:26

问题


My program stops to read anymore lines and ends the program after this procedure like its 'end.' after it (but its not) :

  Procedure BubbleSort;
  var i, j : integer;
  begin
    for i := 0 to count - 1 do begin
      for j := count - 1 downto i do
        if (together[j] > together[j - 1]) then
          Swap(together[j - 1], together[j]);
    end;
  end;

回答1:


I guess the problem is the out of bounds array access. You access index -1. Avoid this by changing the outer loop to:

for i := 1 to count - 1 do begin

I suggest that you enable range checking so that you can learn about out of bounds array access by way of informative runtime errors.



来源:https://stackoverflow.com/questions/29594762/program-stops-after-reading-procedure-delphi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!