append() and appendElement() add a new array element after the last array element. The size of the array will increase by 1.
append() requires a single argument.
appendElement() does require any arguments and adds a new element with the NULL value.
Syntax:
array_variable.append(value)
appendElement()
Usage example:
The methods are applicable only to dynamic arrays and do not have any effect on the static ones.
DEFINE ar DYNAMIC ARRAY OF CHAR(15) ... FOR i = 1 TO 5 #the array has 5 elements LET ar[i]="element "||i END FOR CALL ar.append("element 6") #adds 6th element to the array CALL ar.appendelement() #adds 7th element with the NULL value DISPLAY ar.GetLength() #displays "7"
Also, complex data types can be added into an array of complex data types.
MAIN DEFINE ar DYNAMIC ARRAY OF RECORD f1,f2 INT END RECORD DEFINE rec RECORD f1,f2 INT END RECORD LET rec.f1 = 11 LET rec.f2 = 12 CALL ar.append(rec) DISPLAY ar.GetLength() DISPLAY ar[1].* END MAIN