Regularity

From Maze

(Difference between revisions)
Jump to: navigation, search
(→The Flow of Control)
(→GOTO and the Unbounded Loop)
Line 41:Line 41:
=== GOTO and the Unbounded Loop ===
=== GOTO and the Unbounded Loop ===
−
10 PRINT works as it does because of 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.
+
10 PRINT works as it does because of its repetition of the PRINT statement, repetition that is unconditional: It will continue until something outside the program interrupts it.
−
Programming languages contain two basic types of loops: bounded (also called "finite") and unbounded (or "infinite"). 10 PRINT is an example of an unbounded loop because there is no programmatic condition under which it can be exited. If one is writing a program that is intended to exit and to produce some result, an unbounded loop is an error. The unbounded loop can be used to keep an application (usually an interactive one) running until the system is shut off or rebooted, though, even on a single-threaded system such as the Commodore 64.
+
Programming languages contain two basic types of loops: bounded (also called "finite") and unbounded (or "infinite"). 10 PRINT has the latter kind. If one is writing a program that is intended to exit and to produce some result, an unbounded loop represents a mistake on the programmer's part. The unbounded loop can be used to keep an application (usually an interactive one) running until the system is shut off or rebooted, though, even on a single-threaded system such as the Commodore 64.
−
Bounded loops are those that 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.
+
Bounded loops are those that 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.
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.

Revision as of 16:02, 9 April 2011

View this revision of Regularity.

Personal tools