TakeWhile

TakeWhile[list,crit]

gives elements ei from the beginning of list, continuing so long as crit[ei] is True.

Details

  • TakeWhile can be used on an object with any head, not necessarily List.

Examples

open allclose all

Basic Examples  (2)

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]=

Scope  (1)

Generalizations & Extensions  (1)

Applications  (1)

Properties & Relations  (3)

Possible Issues  (1)

See Also

LengthWhile  NestWhile  While  Take  Select

Tutorials

Introduced in 2007
(6.0)
| Updated in 2008
(7.0)