Post-test conditional loop
The second form of conditional loop is known as a post-test conditional loop. This form of repetition will check the condition after the commands have been executed, initiating another execution of the loop if the condition is not met.
REPEAT
RECEIVE percentage FROM (REAL) KEYBOARD
IF percentage <0 OR percentage > 100 THEN
SEND 鈥淭he percentage you entered is not valid. Please try again.鈥 TO DISPLAY
END IF
UNTIL percentage >=0 OR percentage <=100
In this example the user will enter a percentage which will then be checked by the first line of the IF statement. The loop will continue if the percentage does not meet the condition shown beside UNTIL. In this case the value of percentage needs to be between 0 and 100 inclusive. If it were not between 0 and 100 then the commands within the loop would be repeated until the percentage entered was valid.
Elision
Elision may be used as part of a section of code to allow for the use of natural language. For parts of an algorithm that fall into this category, there would be a comment in natural language (English) within angle brackets < >. For example:
SEND <an appropriate error message> TO DISPLAY
This use of elision suggests that the data contained within the angle brackets is in one of three categories:
- It can be presumed, eg
<populate array with ten random integers>
- It clarifies part of the listing that is necessary but perhaps not relevant to the scenario/question, eg
<loop until end of list>
. This may be used to signify that the loop should iterate over an array until the end of the list, without need for any focus on the number of items held in the array. - It may require further refinement, eg
<find maximum number in list of ten integers>
. In this case it may be necessary to take the detail in the angle brackets and create a section of code that would be capable of finding the maximum number in a list of ten numbers.
It is important to note that use of natural language (English) is only permitted within angle brackets or when writing internal commentary.