ARRAYSEARCH Function

── ARRAYSEARCH ── ( ──<arithmetic expression>── , ─────────────────────►
 ►─<arithmetic expression>── , ─┬─<array row>────────────┬─ ) ──────────┤
                                └─<subscripted variable>─┘

The ARRAYSEARCH function searches for a specific value within an array. The first arithmetic expression is the value being searched for (the target value). The second arithmetic expression is the mask to be used in the search. The third parameter is a row or subscripted variable of an array of type INTEGER, REAL, or BOOLEAN. For information on the subscripted variable, see Arithmetic Assignment.

If the third parameter is an array row, the search begins with the last element of the specified array row; otherwise, the search begins with the element specified by the subscripted variable. Each element, in turn, is retrieved and the Boolean operation AND is performed using the value of the mask and the element as the operands. The Boolean operation AND is also performed on the target value. The results of these two operations are then compared with each other, using the IS operator. For more information on the IS operator, see IS and ISNT Operators.

If the comparison yields the value TRUE, the function returns an integer value equal to the difference between the subscript of the element where the value is found and the subscript of the first element in the array. If the comparison yields the value FALSE, the subscript of the element to be retrieved is decremented by 1, and the search continues until either a match is found or the first element of the array has been examined. If no match is found, –1 is returned. For information on <array row>, see ARRAY Declaration.

The ARRAYSEARCH function can be used on paged (segmented) arrays and unpaged (unsegmented) arrays.