Mr. Martin's programming school

Program flow control

This is where the fun begins! Here you will learn the suff you need to get your programs to appear intelligent.

Up till now you have studied programs that follows a simple flow from the first instruction to the end. Now we will look at how we can alter the way instructions are executed in different ways:


Conditionally

There are currently two ways to control program flow conditionally:
The most common program flow instructin is 'if', often followed by 'else'. Syntax is:

if (condion) [code-block] else [code-block]

Oops, there is a new convention here, actually two:
  1. Things written between '[' and ']' are optional. They may or not may be present.
  2. A code-block is a simple line of program code, or multiple lines of code between curly brackets. You'll understand from the samples below.