Regularity
From Maze
(Difference between revisions)
(Added transistors and processors text) | (Added 10 Print section text) | ||
| Line 1: | Line 1: | ||
=Iteration in 10 Print= | =Iteration in 10 Print= | ||
==The 10 Print Loop (GOTO)== | ==The 10 Print Loop (GOTO)== | ||
| + | As described elsewhere in this book (tk where specifically), one of the key aspects to 10 Print's functionality is its repetition of the print statement – repetition that will continue until either the user manually breaks out of the program or the Commodore 64 it is running on shuts off. (tk finish based on how the descriptions are handled elsewhere.) | ||
==Looping and Iterating== | ==Looping and Iterating== | ||
| + | Programming languages contain two basic types of loops: finite and infinite. 10 Print is an example of an infinite loop because there is no programmatic condition under which it can be exited. As an intentionally infinite loop it is one of a relatively rare breed; though there are a few tasks that are best handled by writing an infinite loop, when a programmer typically thinks about infinite loops they are something to avoid at all costs. Infinite loops not only prevent a program from executing any code outside of the loop but also can occupy a processor and prevent other programs from running. | ||
| + | |||
| + | On the Commodore 64 and most other computers of its era the latter was not a problem as the processor was not capable of running multiple programs simultaneously in any case. The lack of any way out of an infinite loop was also not really a problem on the Commodore 64 since it had a dedicated 'break' key that allowed the user to interrupt any program it was attempting to run. In a one-line program like 10 Print there is neither space nor need for the kind of flow control found in longer programs, and without the other downsides normally associated with an infinite loop there is no reason use a more complex structure. An intentionally infinite loop is usually written when a program is intended to repeat the same action over and over without any significant change to that action being made over time. | ||
| + | |||
| + | Finite loops are exactly what the name would indicate: loops that are designed to end under certain conditions. The exact conditions vary; some will continue until the program reaches a pre-defined exit state while others execute a specific number of times no matter what the result. No matter what the exit conditions are for a specific loop, the fact that there are exit conditions at all implies the programmer is expecting some kind of change in the program to be introduced as a result of the loop's execution. | ||
| + | |||
| + | A common use of finite loops is to create an iterative process. Iteration is a special type of loop where the result of one pass through the loop influences the result of succeeding passes. The simplest example of an iterative process is nothing more than counting. Beginning with an initial value, 1, and adding 1 to it to produces 2. Taking the output from that operation, 2, and performing the same operation again, adding 1, results in 3, and so on until the sequence 1, 2, 3… emerges. Counting to 10, 100, or for one hour no matter what number you end up at are all finite iterative processes; counting until you pass out is an infinite iterative process, even if you never quite make it to infinity. | ||
==10 Print Iterates? (POS)== | ==10 Print Iterates? (POS)== | ||
| + | Based on this description of iteration, it may not be entirely clear that 10 Print is an example of iteration. There are no variables in the code that change value from one pass to the next–there are no variables at all–and the functionality of the code inside the loop never changes. Watching the program execute on screen shows hints that there is something changing beneath the surface, though: the position of the cursor changes every time the loop executes, moving one position to the right. | ||
| + | |||
| + | The position of the cursor is not being managed by 10 Print itself; it is a function of the Commodore 64's KERNAL, a layer of software that lies between BASIC and the machine code executed by the processor to handle input/output functions. Since 10 Print's BASIC code is not controlling the iterative aspect of its function it would be accurate to say that 10 Print is operationally iterative, but the BASIC code is not. This should not preclude examination of 10 Print's iterative nature, however; many iterative processes are dependent upon external or implicit factors influencing their output, and 10 Print's simplicity exposes the power of using simple iterative steps to create a complex construction. | ||
| + | |||
| + | (tk not sure if it would be confusing here to describe RND as an iterative process since it is deterministic…) | ||
==FOR…TO…STEP== | ==FOR…TO…STEP== | ||
| + | (tk add variant that rewrites 10 Print to manually manage the cursor position by poking specific grid locations using BASIC's built-in iteration structure.) | ||
=Iteration Permeating Computing= | =Iteration Permeating Computing= | ||
