This is documentation for Mathematica 8, which was
based on an earlier version of the Wolfram Language.
View current documentation (Version 11.1)

TakeWhile

TakeWhile
gives elements from the beginning of list, continuing so long as is True.
  • TakeWhile can be used on an object with any head, not necessarily List.
Take elements while they are all even:
Use a pure function to take elements while they are all below 10:
Take elements while they are all even:
In[1]:=
Click for copyable input
Out[1]=
 
Use a pure function to take elements while they are all below 10:
In[1]:=
Click for copyable input
Out[1]=
Elements of the list can be any expression:
Use on an expression with head :
Find the digits of before the first occurrence of a 7:
TakeWhile is equivalent to Take of LengthWhile:
TakeWhile gives the entire list if is True for all elements:
TakeWhile gives a subset of the elements returned by Select:
The list terminates for any value of that is not True:
New in 6 | Last modified in 7