Product SiteDocumentation Site

5.3.6.40. Examples

Example 5.159. Array class - examples

array1=.array~of(1,2,3,4)  /* Loads the array */

/* Alternative way to create and load an array */
array2=.array~new(4)  /* Creates array2, containing 4 items */
do i=1 to 4                   /* Loads the array */
  array2[i]=i
end

You can produce the elements loaded into an array, for example:

Example 5.160. Array class - examples

do i=1 to 4
  say array1[i]
end

If you omit any argument values before arguments you supply, the corresponding indexes are skipped in the returned array:

Example 5.161. Array class - examples

directions=.array~of("North","South", ,"West")
do i=1 to 4                                  /* Produces: North          */
  say directions[i]                          /*           South          */
                                             /*           The NIL object */
end                                          /*           West           */

Here is an example using the ~~:

Example 5.162. Array class - examples

z=.array~of(1,2,3)~~put(4,4)
do i = 1 to z~size
  say z[i]              /* Produces:  1 2 3 4 */
end