Program Flow

Programs are recipes which have a particular start spots and special rules on how the computer follows them. In general, a program will start at some "main" routine and continue "downward" one line at a time until the end of the function is reached. Any time another function is encountered, all lines of code inside that function will be completed, before continuing in the current function. Any time an "if" statement is reached, a decision will be made on whether to execute one set of statements or another. Any time a loop is reached, a set of statements may be repeated zero or more time.

Program Flow

Programs are executed in a well defined manner. In the absence of specific "Control Structures" code always "flows":

From Top to Bottom (from left to right)


In a single Line of Code

In any particular line of code, the following order of operations happens:

  1. parenthetical statements are computed first (those inside of parentheses)
  2. everything to the right of an assignment statement
  3. finally, the assignment itself (if there is one)

Road Signs for Code (Control Statements)

Often there are "road signs" that affect which is the next of code to be executed. The common "road signs" are:

There are specific rules in our programming languages that detail what to do when each of the above is encountered. Primarily, for Branches and Loops, some condition is evaluated, and if true, the program takes one course, if false, another.

Function calls are always executed in their entirety and once done, continue with the next line in the program.

Certain commands, such as break, continue, etc can be used to "short circuit" the flow of a program. While useful in a few isolated contexts, these statements should mostly be avoided by the beginning programmer.


Back to Topics List