While
Details

- While[test] does the loop with a null body.
- If Break[] is generated in the evaluation of body, the While loop exits.
- Continue[] exits the evaluation of body, and continues the loop.
- Unless an explicit Return is used, the value returned by While is Null.
- Note that in an example like i=0;While[i<0,tot+=f[i];i++] the roles of ; and , are reversed relative to C-like programming languages.
Examples
open all close allApplications (2)
Tech Notes
Related Guides
Related Links
History
Introduced in 1988 (1.0)
Text
Wolfram Research (1988), While, Wolfram Language function, https://reference.wolfram.com/language/ref/While.html.
CMS
Wolfram Language. 1988. "While." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/While.html.
APA
Wolfram Language. (1988). While. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/While.html
BibTeX
@misc{reference.wolfram_2025_while, author="Wolfram Research", title="{While}", year="1988", howpublished="\url{https://reference.wolfram.com/language/ref/While.html}", note=[Accessed: 13-August-2025]}
BibLaTeX
@online{reference.wolfram_2025_while, organization={Wolfram Research}, title={While}, year={1988}, url={https://reference.wolfram.com/language/ref/While.html}, note=[Accessed: 13-August-2025]}