W1153 Repeat-While Loop
From Coder Merlin
Revision as of 18:11, 12 January 2020 by Chukwuemeka-tinashe (talk | contribs) (→Assembly Language)
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Prerequisites[edit]
Repeat-While Loop[edit]
A repeat-while loop (which is also sometimes called a do-while loop):
- Executes the statements within the body of the loop
- Tests a condition
- If the condition is true, the statements within the body of the loop are again executed
- If the condition is false, execution continues with the statements after the body of the loop
Observe
Observe, Ponder, and Journal: Section 1
- Compare this behavior to that of the while loop. What are the similarities? What are the differences?
- What are the minimum number of times that this loop will execute?
- What is the purpose of the Jump instruction after the consequent?
Flowchart[edit]
Assembly Language[edit]
Let's consider how the above construct is implemented in assembly language:
The statements in the body of the loop are executed. Then, the condition, the Boolean test, is evaluated. If the test evaluates to false, a jump is executed to the alternative, otherwise, execution continues with the consequent. The consequent executes an unconditional jump back to the body of the loop.