Regularity

From Maze

(Difference between revisions)
Jump to: navigation, search
(→BASIC Considered Harmful (Sidebar))
(→Is 10 PRINT Iterating?)
Line 234:Line 234:
== Is 10 PRINT Iterating? ==
== Is 10 PRINT Iterating? ==
−
From the discussion so far, it should be clear that 10 PRINT has an unbounded loop thanks to the unconditional branch at the end. There is nothing in the code, however, to indicate that 10 PRINT is an example of iteration. There are no variables like A that change value from one pass to the next -- there are no variables at all, in fact -- and the code inside the loop, and the way that code works, never changes. In the most strightforward sense, the BASIC program <code>10 PRINT CHR$(205.5+RND(1)); : GOTO 10</code> does not iterate.
+
From the discussion so far, it should be clear that 10 PRINT has an unbounded loop thanks to the unconditional branch at the end. 10 PRINT clearly repeats. There is nothing in the code, however, to indicate that 10 PRINT is an example of iteration in the more mathematical or computational sense. There are no variables like A that change value from one pass to the next -- there are no variables at all, in fact -- and the code inside the loop, and the way that code works, never changes. In the most straightforward computing sense, the BASIC program <code>10 PRINT CHR$(205.5+RND(1)); : GOTO 10</code> does not iterate.
Watching the program execute on screen shows hints that there is something changing as it runs, though: the position where a new character is displayed changes every time the loop executes, moving one location to the right until it reaches the 40th column; then, the display of characters continues on the next line in column 1. The entire contents of the screen also moves up by two lines, with the top two lines disappearing, once the display of characters reaches the bottom left position.
Watching the program execute on screen shows hints that there is something changing as it runs, though: the position where a new character is displayed changes every time the loop executes, moving one location to the right until it reaches the 40th column; then, the display of characters continues on the next line in column 1. The entire contents of the screen also moves up by two lines, with the top two lines disappearing, once the display of characters reaches the bottom left position.
−
None of this is a direct result of any BASIC statements included in 10 PRINT. Displaying strings on the screen generally has this effect, since BASIC's PRINT command calls the Commodore 64 KERNAL's CHAROUT routine and produces output in this way. So, while 10 PRINT is not an iterative program, it invokes the iterative behavior of PRINT. In this case, the behvaior is a sort of incrementing, because ";" is used to display the next character immediate after the previous one and a string that is one character long is displayed in each pass. 10 PRINT's simplicity exposes the power of using simple, iterative steps to create a complex construction.
+
None of this is a direct result of any BASIC statements included in 10 PRINT. Displaying strings on the screen generally has this effect, since BASIC's PRINT command calls the Commodore 64 KERNAL's CHAROUT routine and produces output in this way. So, while 10 PRINT is not an iterative program, it invokes the iterative behavior of PRINT. In this case, the behvaior is a sort of horizontal incrementing, because ";" is used to display the next character immediate after the previous one and a string that is one character long is displayed in each pass. 10 PRINT exposes the power of using simple, iterative steps to create a complex construction.
= Works Cited =
= Works Cited =

Revision as of 14:49, 28 July 2011

View this revision of Regularity.

Personal tools