Mathematica 9 is now available
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Mathematica > Core Language > Functional Programming > Functional Iteration > LengthWhile >
Mathematica > Core Language > Procedural Programming > Looping Constructs > Functional Iteration > LengthWhile >

LengthWhile

LengthWhile
gives the number of continuous elements starting at the beginning of list for which is True.
Find the length of the run of elements below 10:
Find the length of the run of elements below 10:
In[1]:=
Click for copyable input
Out[1]=
Elements of the list can be any expression:
Use on an expression with head f:
The result is the same as for a list of the values:
Find the length of the run of digits in before a 7 occurs:
LengthWhile gives the length of the result from TakeWhile:
LengthWhile is equal to Length if is True for all elements:
Otherwise it is 1 less than the first position for which is not True:
The count terminates for any value of that is not True:
New in 6 | Last modified in 7
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team
Format:   HTML  |  CDF