Program Flow

Program flow is the order in which a computer follows the instructions a programmer gives it.

Normally, a computer will follow the instructions from the first to the last and end the program when there is no more code to run.

; pseudo code 

Display "Hi"
Display "I'm a computer game."
Display "Not really, I'm just an example."
End Game

In the example above, the computer will run each line in order and end the program after line 3 when there is no more code to run.

Conditional Statements

A conditional statement is a construct which allows code to be executed conditionally depending on the value of an expression.

IF

An If statement checks an expression and runs code depending on the evaluation of an expression. If the expression is true then the code will be run. If it is false, the code will not be executed.

Loops

Outdated Program Flow

GOTO

GOTO will skip to a specific line in a program.

1 PRINT "Hi"
2 GOTO 5
3 PRINT "Last line was 6"
4 GOTO 7
5 PRINT "Last line was 2"
6 GOTO 3
7 PRINT "Last line was 4"

This will output :

Hi
Last line was 2
Last line was 6
Last line was 4

GOSUB

GOSUB will send the program flow to a line where it will continue until it finds RETURN. Then, it will return to just below the original GOSUB.

1 PRINT "About to go on a subroutine."
2 GOSUB 5
3 PRINT "I have returned."
4 END
5 PRINT "I'm on a subroutine."
6 PRINT "I'm about to return."
7 RETURN

This will output :

About to go on a subroutine.
I'm on a subroutine.
I'm about to return.
I have returned.

Subroutines

  • Write me

Functions

  • Write me

Related Pages

Backlinks

These pages link back to this page. You may find them helpful.

Links

Categories: Program Flow : Programming
page_revision: 28, last_edited: 1247023171|%e %b %Y, %H:%M %Z (%O ago)