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:

Wolfram Research (2007), TakeWhile, Wolfram Language function, https://reference.wolfram.com/language/ref/TakeWhile.html (updated 2008).

Text

Wolfram Research (2007), TakeWhile, Wolfram Language function, https://reference.wolfram.com/language/ref/TakeWhile.html (updated 2008).

CMS

Wolfram Language. 2007. "TakeWhile." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2008. https://reference.wolfram.com/language/ref/TakeWhile.html.

APA

Wolfram Language. (2007). TakeWhile. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TakeWhile.html

BibTeX

@misc{reference.wolfram_2023_takewhile, author="Wolfram Research", title="{TakeWhile}", year="2008", howpublished="\url{https://reference.wolfram.com/language/ref/TakeWhile.html}", note=[Accessed: 18-March-2024 ]}

BibLaTeX

@online{reference.wolfram_2023_takewhile, organization={Wolfram Research}, title={TakeWhile}, year={2008}, url={https://reference.wolfram.com/language/ref/TakeWhile.html}, note=[Accessed: 18-March-2024 ]}