October 2018
Intermediate to advanced
404 pages
8h 50m
English
A while loop is explicitly started and stopped by true/false choice points. These can look very complicated, but they resolve to a limited set of tests for a single condition:
X = 0 Y = 20 while (X != Y): print (X), X = X + 1
This Python 3 loop will print the value of X over and over until it reaches 10, then stop. It would work exactly the same if we said while X < Y, because the loop structure is testing X as it is incremented. A more complicated loop, using a random number for the incrementor element, might go on for much longer (or not) before it randomly hits on a value of X that was the equivalent of Y:
It is obvious that the program is testing the looping condition each time. Here is an example of ...