Difference between revisions of "W1153 Repeat-While Loop"

From Coder Merlin
Line 23: Line 23:
Let's consider how the above construct is implemented in assembly language:
Let's consider how the above construct is implemented in assembly language:
{{ResponsiveImage|[[File:Repeat-While Loop Assembly.png]]}}
{{ResponsiveImage|[[File:Repeat-While Loop Assembly.png]]}}
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.


== Topic Headers ==
== Topic Headers ==

Revision as of 18:11, 12 January 2020

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Infinite Loop 1

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
ObserveObserveIcon.png
Observe, Ponder, and Journal: Section 1
  1. Compare this behavior to that of the while loop. What are the similarities? What are the differences?
  2. What are the minimum number of times that this loop will execute?
  3. What is the purpose of the Jump instruction after the consequent?

Flowchart[edit]

   Repeat-While Loop Flowchart.png

Assembly Language[edit]

Let's consider how the above construct is implemented in assembly language:

   Repeat-While Loop Assembly.png

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.

Topic Headers[edit]

Key Concepts[edit]

Exercises[edit]

References[edit]