Until

Until[test,body]

evaluates body and then test, repetitively, until test first gives True.

Details

  • Until[test] evaluates test repeatedly, effectively with a null body.
  • If Break[] is generated in the evaluation of body, the Until loop exits.
  • Continue[] exits the evaluation of body and continues the loop.
  • Unless an explicit Return is used, the value returned by Until is Null.
  • Note that in an example like i=0;Until[i>10,tot+=f[i];i++], the roles of ; and , are reversed relative to C-like programming languages.

Examples

open allclose all

Basic Examples  (1)

Print and increment n until the condition n>3 is satisfied:

Scope  (1)

Break breaks out of the Until loop:

Applications  (2)

Compute the GCD of two numbers:

Count the number of iterations in a fixed-point calculation:

Properties & Relations  (2)

Until[test,body] evaluates body before test:

While[test,body] evaluates test before body:

Until and While require opposite tests to reproduce similar behavior:

However, the test is evaluated one more time in the While loop:

Wolfram Research (2022), Until, Wolfram Language function, https://reference.wolfram.com/language/ref/Until.html.

Text

Wolfram Research (2022), Until, Wolfram Language function, https://reference.wolfram.com/language/ref/Until.html.

CMS

Wolfram Language. 2022. "Until." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/Until.html.

APA

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

BibTeX

@misc{reference.wolfram_2024_until, author="Wolfram Research", title="{Until}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Until.html}", note=[Accessed: 26-April-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_until, organization={Wolfram Research}, title={Until}, year={2022}, url={https://reference.wolfram.com/language/ref/Until.html}, note=[Accessed: 26-April-2024 ]}