I am switching from C # to Delphi 2009, I really like it.
I wrote a binary search procedure that works great. I added a simple if-else statement at the end of my program, and it just doesn't work! I see nothing wrong with that, and I am ashamed to say that I am stuck. Please, help!
procedure BinSearch;
var
min,max,mid, x: integer;
A : array[0..4] of integer;
rslt : integer;
begin
writeln('binary search');
A[0] := 34; A[1] := 65; A[2] := 98; A[3] := 123; A[4] := 176;
listarray(a);
x := 62;
min := 0;
max := 4;
repeat
begin
mid := (min + max) div 2;
if x > A[mid] then
min := mid + 1
else
max := mid - 1;
end;
until (A[mid] = x) or (min > max);
writeln(mid);
writeln(a[mid]);
if A[mid] = x then
rslt := mid
else
rslt := not mid;
if 54 = 65 then
rslt := mid
else
rslt := not mid;
end;
This if A[mid] = x thenthat does not work. when debugging neither true nor false branches the fire, the debugger just jumps right above them. Also a tag if 54 = 65 then, which is just a test, does the same.
If inside the repeat loop it works fine.
- proc, proc, , - proc, ;, - , . , !