WOLFRAM

Copy to clipboard.
Break[]

exits the nearest enclosing Do, For, Until or While.

Details

  • Break[] takes effect as soon as it is evaluated, even if it appears inside other functions.
  • After a Break the value Null is returned from the enclosing control structure.
  • The function of Break can also be achieved using Throw and Catch.

Examples

open allclose all

Basic Examples  (1)Summary of the most common use cases

Break out of the Do when i is larger than 2:

Scope  (1)Survey of the scope of standard use cases

Break out of a Do loop:

Break out of a For loop:

Out[2]=2

Break out of a While loop:

Out[3]=3

Applications  (1)Sample problems that can be solved with this function

Test the condition of a loop during or at the end of the loop:

Properties & Relations  (2)Properties of the function, and connections to other functions

Use Throw and Catch instead of Break:

Out[1]=1

Continue skips the rest of a loop, but resumes with the next iteration:

Wolfram Research (1988), Break, Wolfram Language function, https://reference.wolfram.com/language/ref/Break.html (updated 2022).
Copy to clipboard.
Wolfram Research (1988), Break, Wolfram Language function, https://reference.wolfram.com/language/ref/Break.html (updated 2022).

Text

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

Copy to clipboard.
Wolfram Research (1988), Break, Wolfram Language function, https://reference.wolfram.com/language/ref/Break.html (updated 2022).

CMS

Wolfram Language. 1988. "Break." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/Break.html.

Copy to clipboard.
Wolfram Language. 1988. "Break." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2022. https://reference.wolfram.com/language/ref/Break.html.

APA

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

Copy to clipboard.
Wolfram Language. (1988). Break. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Break.html

BibTeX

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

Copy to clipboard.
@misc{reference.wolfram_2025_break, author="Wolfram Research", title="{Break}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/Break.html}", note=[Accessed: 26-March-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_break, organization={Wolfram Research}, title={Break}, year={2022}, url={https://reference.wolfram.com/language/ref/Break.html}, note=[Accessed: 26-March-2025 ]}

Copy to clipboard.
@online{reference.wolfram_2025_break, organization={Wolfram Research}, title={Break}, year={2022}, url={https://reference.wolfram.com/language/ref/Break.html}, note=[Accessed: 26-March-2025 ]}