Regularity
From Maze
(Difference between revisions)
(→Repeating: Regularity in Time and Process) | (→Conditional and Unconditional Branching) | ||
| Line 25: | Line 25: | ||
=== Conditional and Unconditional Branching === | === Conditional and Unconditional Branching === | ||
| − | At a low level, an executing program can either continue to process the next instruction or can move out of sequence to process a different instruction. Just as a reader of a text will typically move to the next word or line, the usual case in the execution of a program is to move to the next instruction. This involves incrementing the program counter so that it points to the place where code is located in memory. If the current instruction is one that can change the flow of control, however, the program may jump or branch to a new memory location and a new piece of code. | + | There are two essential ways that the flow of control can change and a program can "branch," or continue at a new point. An unconditional branch always directs the program to jump to a new location, like the instruction "Go directly to Jail -- do not pass Go" in Monopoly. The assembly mnemonic for an unconditional branch is JMP; the corresponding BASIC keyword is GOTO. |
| − | |||
| − | There are two ways to branch. An unconditional branch always directs the program to jump to a new location, like the instruction "Go directly to Jail -- do not pass Go" in Monopoly. The assembly mnemonic for an unconditional branch is JMP; the corresponding BASIC keyword is GOTO. | ||
When an unconditional branch is used to point back to an earlier instruction, it can accomplish repetition in process. In 10 PRINT, the GOTO command is used to cause the program to loop, so that the PRINT command is repeated again and again. | When an unconditional branch is used to point back to an earlier instruction, it can accomplish repetition in process. In 10 PRINT, the GOTO command is used to cause the program to loop, so that the PRINT command is repeated again and again. | ||
