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 >
Mathematica > Core Language > Procedural Programming > Looping Constructs > Functional Iteration >

LengthWhile

Updated In 7 Graphic
LengthWhile[list, crit]
gives the number of continuous elements ei starting at the beginning of list for which crit[ei] 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 Pi before a 7 occurs:
LengthWhile gives the length of the result from TakeWhile:
LengthWhile is equal to Length if crit[ei] is True for all elements:
Otherwise it is 1 less than the first position for which crit[ei] is not True:
The count terminates for any value of crit[ei] 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