This task is about arrays.

For hashes or associative arrays, please see Creating an Associative Array.

For a definition and in-depth discussion of what an array is, see Array.



Task

Show basic array syntax in your language.

Basically, create an array, assign a value to it, and retrieve an element   (if available, show both fixed-length arrays and
dynamic arrays, pushing a value into it).

Please discuss at Village Pump:   Arrays.

Please merge code in from these obsolete tasks:

   Creating an Array
   Assigning Values to an Array
   Retrieving an Element of an Array


Related tasks

   Collections
   Creating an Associative Array
   Two-dimensional array (runtime)


PROC Main()
  BYTE i
 
  ;array storing 4 INT items with initialized values
  ;negative values must be written as 16-bit unsigned numbers
  INT ARRAY a=[3 5 71 65535]
 
  ;array storing 4 CARD items whithout initialization of values
  CARD ARRAY b(3)
 
  ;array of BYTE items without allocation,
  ;it may be used as an pointer for another array
  BYTE ARRAY c
 
  ;array of 1+7 CHAR items or a string
  ;the first item stores length of the string
  CHAR ARRAY s="abcde"
 
  PrintE("Array with initialized values:")
  FOR i=0 TO 3
  DO
    PrintF("a(%I)=%I ",i,a(i))
  OD
  PutE() PutE()
 
  PrintE("Array before initialization of items:")
  FOR i=0 TO 3
  DO
    PrintF("b(%I)=%B ",i,b(i))
  OD
  PutE() PutE()
 
  FOR i=0 TO 3
  DO
    b(i)=100+i
  OD
  PrintE("After initialization:")
  FOR i=0 TO 3
  DO
    PrintF("b(%I)=%B ",i,b(i))
  OD
  PutE() PutE()
 
  PrintE("Array of chars. The first item stores the length of string:")
  FOR i=0 TO s(0)
  DO
    PrintF("s(%B)='%C ",i,s(i))
  OD
  PutE() PutE()
 
  PrintE("As the string:")
  PrintF("s=""%S""%E%E",s)
 
  c=s
  PrintE("Unallocated array as a pointer to another array. In this case c=s:")
  FOR i=0 TO s(0)
  DO
    PrintF("c(%B)=%B ",i,c(i))
  OD
RETURN