Skip to main content
Engineering LibreTexts

13.4: Repeat Until Loop

  • Page ID
    11307
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Introduction to Test After Loops

    There are two commonly used test after loops in the iteration (or repetition) category of control structures. They are: do while and repeat until. This module covers the: repeat until.

    Understanding Iteration in General - repeat until

    The concept of iteration is connected to possibly wanting to repeat an action. Like all control structures we ask a question to control the execution of the loop. The term loop comes from the circular looping motion that occurs when using flowcharting. The basic form of the repeat until loop is as follows:

    repeat
      some statements or action
      some statements or action
      some statements or action
      update the flag
    until the answer to the question becomes true 
    

    In every language that I know the question (called a test expression) is a Boolean expression. The Boolean data type has two values – true and false. Let's rewrite the structure to consider this:

    repeat
      some statements or action
      some statements or action
      some statements or action
      update the flag
    until expression becomes true 
    

    Within the repeat until control structure there are three attributes of a properly working loop. They are:

    • Action or actions
    • Update of the flag
    • Test expression

    The English phrasing is, "You repeat the action until the expression becomes true". This is looping on the false. When the test expression becomes true, you stop the loop and go on with the next item in the program. Notice, because this is a test after loop the action will always happen at least once. It is called a "test after loop" because the test comes after the action. It is also sometimes called a post-test loop, meaning the test is post (or Latin for after) the action and update.

    The repeat until Structure within C++

    Well, it just does not exist. Most programming languages have either the do while or the repeat until control structures, but not both.

    Definitions

    Repeat Until
    A test after iteration control structure that is not available in C++.

    This page titled 13.4: Repeat Until Loop is shared under a CC BY license and was authored, remixed, and/or curated by Kenneth Leroy Busbee (OpenStax CNX) .

    • Was this article helpful?