Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

help!

omair19omair19 Member Posts: 39
while going through delphi tutorial i came accross a code snippet that i am having problems understanding,i am writing the problems as comments in the code
[code] procedure MakeZero(var Arr: Array of Double)
(* in pascal array declaration was like this arr : array [1..50] of integer they wrote array of double but didnt specify where to where (i mean like 1..50)*)
var i:integer;
begin
for i:= Low(Arr) to High(Arr) + 1 do Arr[i] := 0;
(*what is this low(arr) and high(arr)and why did they add +1 looping can be done as say like for i:=1 to 10 do we dont write i:=1 to 10 +1*)
end;
[/code]
sorry for asking basic questions i am a self taught so i am having alot of problems
i am curruntly studying about.com's tutorial if anyone else learned delphi online can you tell me which tutorial is better?
thanks in advance!

Comments

  • zibadianzibadian Member Posts: 6,349
    : while going through delphi tutorial i came accross a code snippet that i am having problems understanding,i am writing the problems as comments in the code
    : [code] procedure MakeZero(var Arr: Array of Double)
    : (* in pascal array declaration was like this arr : array [1..50] of integer they wrote array of double but didnt specify where to where (i mean like 1..50)*)
    : var i:integer;
    : begin
    : for i:= Low(Arr) to High(Arr) + 1 do Arr[i] := 0;
    : (*what is this low(arr) and high(arr)and why did they add +1 looping can be done as say like for i:=1 to 10 do we dont write i:=1 to 10 +1*)
    : end;
    : [/code]
    : sorry for asking basic questions i am a self taught so i am having alot of problems
    : i am curruntly studying about.com's tutorial if anyone else learned delphi online can you tell me which tutorial is better?
    : thanks in advance!
    :
    :
    If the dimension of an array parameter isn't specified, then the calling code specifies it. For example:
    [code]
    var
    MyArray: array[0..10] of double;
    begin
    MakeZero(MyArray);
    end;
    [/code]
    makes the Arr parameter an array[0..10] array.
    This code makes it a 100..150 array:
    [code]
    var
    MyArray2: array[100..150] of double;
    begin
    MakeZero(MyArray2);
    end;
    [/code]

    That +1 is wrong. The High() function returns the index of the last element of the array. The loop should read:
    [code]
    for i:= Low(Arr) to High(Arr) do Arr[i] := 0;
    [/code]
    For the first example it becomes:
    [code]
    for i:= 0 to 10 do Arr[i] := 0;
    [/code]
    And the second:
    [code]
    for i:= 100 to 150 do Arr[i] := 0;
    [/code]
    without needing to change the source code.
Sign In or Register to comment.