WHEREFIRST Procedure
Standard Library procedure that returns the index of the first 1 in array of 0’s and 1’s.
 
note
For large binary arrays, WHEREFIRST is faster than (WHERE(b))(0).
Usage
WHEREFIRST, b, i
Input Parameters
b — Array containing only 0’s and 1’s.
i — (I/O) Index from which the forward search begins.
Output Parameters
i — (I/O) Index of the first occurrence of 1 in b which is greater than or equal to the input index.
Discussion
Given an array of 0's and 1's and a 1D index i, WHEREFIRST returns the 1D index j of the first 1 such that j i. For large binary arrays (arrays that contain only ones and zeros) WHEREFIRST is much more efficient than using WHERE to find the first nonzero element.
 
note
It is important that the array contain only zeros and ones, otherwise results are unpredictable. For performance reasons, the input array is not checked for invalid values.
Example
i=1
WHEREFIRST,[0,0,0,1,1,0,1,0,1],i
PM, i
Output
3
See Also