arrayspascalfreepascalstatic-initialization

Pascal - hard-coding data in array - shortcut


Here's what I'm trying to do:

T[1]:=5;
T[2]:=3;
.
.
.
T[9]:=20;

Is there a shortcut to achieving this where I can assign the values in a single line?


Solution

  • I could not find this in any of the documentations but I tried this and it works!

    Here's the method used with a complete example:

    Program StrangeArray;
    
    Var T: Array[1..5] of Integer = (554,434,144,343,525);
        x:integer;
    
    Begin
    For x:=1 to 5 Do
        Begin
        Writeln(T[x]);
    
        End;
    
    End.
    

    Hope this is useful for others as well.