n = count ( variable ) ;
list variable
- An array (of any type or size) identifier, literal, or from an expression.
int n
- 0 - n
A count of 0 through n elements.
The STATUS variable is set to $ACKNOWLEDGE
%ARGUMENT : Invalid arguments. Usage: n = count ( variable ) ;
The count function returns the number of elements in a list or vector. From a dynamic list, which is the default variable type, the count function must hop through each element in the list to get the current count, so it is inefficient for large lists. For example, the second form of the for statement below is more efficient:
/* List of 1000+ elements */ list a = { 1,2,3,4,.......,1001,1002,...} ; /* count(a) is done each time through the loop!! */ for (i=0;i<count(a);i++) { .... } /* count(a) is done upfront, loop is now faster */ n = count a ; for (i=0;i<n;i++) { ... }