delete( ) example
The following code removes elements from the array aTest that have the letter "e" in them.
aTest = {"alpha", "beta", "gamma", "delta"}
nDeleted = 0 // Count deleted elements
// Loop through array backwards
for nElement = aTest.size to 1 step -1
if "e" $ aTest[ nElement ] // If element contains "e"
aTest.delete( nElement ) // Delete element
nDeleted++ // Increment delete count
endif
endfor
if nDeleted > 0
aTest.size := aTest.size - nDeleted // Discard false elements
endif
// Display elements (looping forward)
for nElement = 1 to aTest.size
? aTest[ nElement ]
endfor
The loop to delete the elements runs through the array backwards because delete( ) moves all remaining elements forward. You would then have to recheck the same element number and juggle the element counter. It’s simpler to just loop through the array backwards.