PATH: Instructional Server> COP 2000> Examples> Counting Loop>

Text-based Documentation for Counting Controlled Repetition Structure Examples


This web page contains text-based alternatives to the graphic-based elements (flowcharts and columnar tables) shown in the web page An Example of a Counting Loop (Repetition Structure). That page offers examples of two different control structures, "leading decision" repetition and "trailing decision" repetition. The first two items below on this web page relate to the leading decision loop example. The final two items relate to the trailing decision loop example.

Leading Decision Loop Algorithm Outline (alternative to a flowchart)

It is important to clearly describe logical control structures that involve branching away from the simple sequential flow of steps and the conditions upon which they are based. Outlines are well suited to this task because of the hierarchical nature of their lettered and numbered steps. Analysts often employ indentation using tabs or spaces to help clarify step subordination. If your rendering software cannot indicate the presence of such "whitespace" characters, be give careful attention to the labeling of the steps to determine the subordination of the steps.

Note: in the document below, "[CR]" represents the carriage return and/or line feed sequence necessary to start a new line of output.

A. Start "Leading Decision Counting Loop Example"
B. Assign the value First into C.("Initialization of the counter")
C. While C is less than or equal to Final ("Test for passage/exit"), do a loop pass:
   C.1. Display the value in C and a [CR]. ("Loop body")
   C.2. Increase C by the value in Step. ("Loop increment")
   C.3. Go back to loop test. ("Loopback")
D. End

The steps above contain the four parts found in every counting controlled loop. These are:

Leading Decision Loop Tracing List (alternative to a columnar Tracing Chart)

The list below is an alternative to the traditional columnar Tracing Chart used to track the values of data items as they are stored in main memory and to track the true or false results of conditional tests within an algorithm. Each line below indicates a change to one of those items in the format "Identifier or condition: value or result". The order of the lines below indicates the order in which the changes occurred. These should be studied in combination with the Test Softcopies shown on the An Example of a Counting Loop (Repetition Structure).

C: 1
C <= Final: True
C: 1
C <= Final: True
C: 2
C <= Final: True
C: 3
C <= Final: True
C: 4
C <= Final: True
C: 5
C <= Final: True
C: 6
C <= Final: False

Trailing Decision Loop Algorithm Outline (alternative to a flowchart)

It is important to clearly describe logical control structures that involve branching away from the simple sequential flow of steps and the conditions upon which they are based. Outlines are well suited to this task because of the hierarchical nature of their lettered and numbered steps. Analysts often employ indentation using tabs or spaces to help clarify step subordination. If your rendering software cannot indicate the presence of such "whitespace" characters, be give careful attention to the labeling of the steps to determine the subordination of the steps.

Note: in the document below, "[CR]" represents the carriage return and/or line feed sequence necessary to start a new line of output.

A. Start "Trailing Decision Counting Loop Example"
B. Assign the value First into C. ("Initialization of the counter")
C. Do a loop pass:
   C.1. Display the value in C and a [CR]. ("Loop body")
   C.2. Increase C by the value in Step. ("Loop increment")
   C.3. If C is less than or equal to Final ("Test for passage/exit"), do another pass.
D. End

The steps above contain the four parts found in every counting controlled loop. These are:

Trailing Decision Loop Tracing List (alternative to a columnar Tracing Chart)

The list below is an alternative to the traditional columnar Tracing Chart used to track the values of data items as they are stored in main memory and to track the true or false results of conditional tests within an algorithm. Each line below indicates a change to one of those items in the format "Identifier or condition: value or result". The order of the lines below indicates the order in which the changes occurred. These should be studied in combination with the Test Softcopies shown on the An Example of a Counting Loop (Repetition Structure).

C: 1
C: 2
C <= Final: True
C: 3
C <= Final: True
C: 4
C <= Final: True
C: 5
C <= Final: True
C: 6
C <= Final: False
PATH: Instructional Server> COP 2000> Examples> Counting Loop>