Although normal for loops makes programming easier, it does not always work in every situation, as it is not always relevant to count upwards. Luckily, there is a special kind of counted loops called decreasing loops. Similar to its counterpart, the counter value is both declared and contained by the loop itself. They are formed by keywords 'for decreasing', followed the by the control variable, a colon, the starting value, a dot-dot, and the ending value. The following is an example:
for decreasing controlVariable : 5 .. 2 put “The Alluring Turing” end for
In the example above, it is obvious that the control variable is never initialized, however a value of the starting value does get stored in it (in this case 5). As a loop with specified boundries, the "internal countdown" from 5 to 2 begins, each time testing if the final value (2) is reached. If it is, the loop exits and the remainder of the code is executed. Otherwise, the loop instructions are executed once again and the control variable's value is decreased by 1.
A common mistake that people make is to put the switch the values in the range of the counted loop so that the ending value is in the place of the starting value and vice versa.Please remember that Turing counts for loops from left to right, not the opposite. An easy way to remember this is by thinking the dot-dot as a minus sign.
However, just like the increasing for loops, this version can also be written in a different way. This is accomplished by using the opposite of an accumulator, called a deccumulator. As its name suggests, it is a counter value that decreases. For instance, consider the following program program fragment:
countingDecreasingIntegers := 5 loop exit when countingDecreasingIntegers = 2 put “The Alluring Turing” countingDecreasingIntegers = countingDecreasingIntegers – 1 end loop
Though longer, this version gives you a clearer view of what is happening.