- Entertainment & Pop Culture
- Geography & Travel
- Health & Medicine
- Lifestyles & Social Issues
- Literature
- Philosophy & Religion
- Politics, Law & Government
- Science
- Sports & Recreation
- Technology
- Visual Arts
- World History
- On This Day in History
- Quizzes
- Podcasts
- Dictionary
- Biographies
- Summaries
- Top Questions
- Week In Review
- Infographics
- Demystified
- Lists
- #WTFact
- Companions
- Image Galleries
- Spotlight
- The Forum
- One Good Fact
- Entertainment & Pop Culture
- Geography & Travel
- Health & Medicine
- Lifestyles & Social Issues
- Literature
- Philosophy & Religion
- Politics, Law & Government
- Science
- Sports & Recreation
- Technology
- Visual Arts
- World History
- Britannica Classics
Check out these retro videos from Encyclopedia Britannica’s archives. - Demystified Videos
In Demystified, Britannica has all the answers to your burning questions. - #WTFact Videos
In #WTFact Britannica shares some of the most bizarre facts we can find. - This Time in History
In these videos, find out what happened this month [or any month!] in history. - Britannica Explains
In these videos, Britannica explains a variety of topics and answers frequently asked questions.
- Buying Guide
Expert buying advice. From tech to household and wellness products. - Student Portal
Britannica is the ultimate student resource for key school subjects like history, government, literature, and more. - COVID-19 Portal
While this global health crisis continues to evolve, it can be useful to look to past pandemics to better understand how to respond today. - 100 Women
Britannica celebrates the centennial of the Nineteenth Amendment, highlighting suffragists and history-making politicians. - Britannica Beyond
We’ve created a new place where questions are at the center of learning. Go ahead. Ask. We won’t mind. - Saving Earth
Britannica Presents Earth’s To-Do List for the 21st Century. Learn about the major environmental problems facing our planet and what can be done about them! - SpaceNext50
Britannica presents SpaceNext50, From the race to the Moon to space stewardship, we explore a wide range of subjects that feed our curiosity about space!
The repeat/until loop is a loop that executes a block of statements repeatedly, until a given condition evaluates to true. The condition will be re-evaluated at the end of each iteration of the loop, allowing code inside the loop to affect the condition in order to terminate it.
Since the condition is evaluated at the end of each iteration, a repeat/until loop will always be executed at least once, even if the condition is already true when execution arrives at the loop.
As an alternative to the repeat/until block loop, the while/do loop will evaluate a condition at the start of each iteration, thus providing a loop that can skip even the first iteration.
Syntax
The basic syntax for a repeat/until loop looks like this:
repeat DoSomething[]; DoSomethingElse[]; until x ≥ 10;where a conditional expression is specified after the closing until keyword, and a list of statements can be provided between the repeat and until keywords.
Nullable Conditions
The condition expression for the repeat/until loop must be of Boolean or Nullable Boolean type.
If the condition is a simple boolean, the repeat/until loop will execute as long as the condition evaluates to false [in other words until it is true].
If the condition is a Nullable Boolean type, then the additional case of the condition evaluating to nil needs to be considered. While a nil nullable boolean strictly speaking is not equivalent to false, the repeat/until loop treats them the same, and will continue executing the loop if the condition evaluates to either nil or false. Only a value of true will terminate the loop.
This behavior symmetrically extends to if/then statements and while/do loops, which also treat a nil condition as equivalent to false.
repeat/until Loops and begin/end blocks.
Unlike most other statements, and all the other loop types, the repeat/until loop is a block statement, and encloses a list of statements, rather than looping an individual statement. As such, a separate or explicit begin/end block statement is not necessary in order to execute a loop with two or more statements.
Prematurely Exiting the Loop or a Loop Iteration
Like all loops, repeat/until loops can be exited prematurely using the break and exit statements, and a single loop iteration can be cut short by using the continue statement, which jumps to the next loop iteration.
See Also
- Loop Statements
- Flow Control Statements
- begin/end Block Statements
- for and while/do loops
- loop loops, also referred to as Infinite Loops