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

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
Ask a question about this page  |  Suggest an improvement  |  Leave a message for the team
Format:   HTML  |  CDF