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:

Use a pure function to take elements while they are all below 10:

Scope  (1)

Elements of the list can be any expression:

Generalizations & Extensions  (1)

Use on an expression with head f:

Applications  (1)

Find the digits of before the first occurrence of a 7:

Properties & Relations  (3)

TakeWhile is equivalent to Take of LengthWhile:

TakeWhile gives the entire list if crit[ei] is True for all elements:

TakeWhile gives a subset of the elements returned by Select:

Possible Issues  (1)

The list terminates for any value of crit[ei] that is not True:

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