$ ADA/LIST ARRAY1 1 -- SAMPLE TO DEMONSTRATE SIMPLE ARRAYS 2 3 with TEXT_IO ; use TEXT_IO ; 4 5 procedure ARRAY1 is 6 7 -- dimension the array BALANCES with subscripts ranging form 1 to 20 8 -- and having each element of the array be a floating point number 9 BALANCES : array ( 1..20 ) of FLOAT := ( 1 .. 20 => 0.0 ) ; 10 11 -- declare the variable OPEN_ACCOUNTS to be integer and initialized 12 -- to zero. This will be the number of entries used in the array. 13 OPEN_ACCOUNTS : INTEGER := 0 ; 14 15 package INT_IO is new INTEGER_IO ( INTEGER ) ; use INT_IO ; 16 package FLT_IO is new FLOAT_IO ( FLOAT ) ; use FLT_IO ; 17 18 begin 19 20 -- zero out the array in execution 21 for I in 1 .. 20 loop -- 1..20 should be BALANCES'RANGE 22 BALANCES ( I ) := 0.0 ; 23 end loop ; 24 25 -- increment the array pointer and put in data 26 OPEN_ACCOUNTS := OPEN_ACCOUNTS + 1 ; 27 BALANCES ( OPEN_ACCOUNTS ) := 1.5 ; 28 29 -- any integer expression can be used as a subscript 30 BALANCES ( OPEN_ACCOUNTS + 1 ) := 0.732_175E6 ; 31 -- note: floating point numbers can use scientific notation 32 -- but be sure to use at least one digit before and after the point 33 34 PUT ( OPEN_ACCOUNTS ) ; 35 PUT_LINE ( " open accounts " ) ; 36 PUT ( BALANCES ( OPEN_ACCOUNTS ) ) ; 37 PUT_LINE ( " is balance, no formatting " ) ; 38 PUT ( BALANCES ( OPEN_ACCOUNTS ) , FORE => 5, AFT => 2, EXP => 0 ) ; 39 PUT_LINE ( " is balance, named parameters " ) ; 40 PUT ( BALANCES ( OPEN_ACCOUNTS ) , 5 , 2 , 0 ) ; 41 PUT_LINE ( " is balance, positional parameters " ) ; 42 43 end ARRAY1 ; $ ACS LINK ARRAY1 $ RUN ARRAY1 1 open accounts 1.50000E+00 is balance, no formatting 1.50 is balance, named parameters 1.50 is balance, positional parameters