Reference languagePost-condition loop

It is important to read and understand a formal language. Declaring variables and data types, using selection statements, iteration and using operators are comprehensions required before coding.

Part ofComputing ScienceSoftware design and development

Post-condition loop

The second form of conditional loop is known as a post-condition 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 “The 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.