Unit 1.1 - An Introduction to Programming

There are three fundamental concepts in programming (in any language!)

sequence of statements
if statements
looping

Sequencing is like a classic recipe. Do this task, then this task, then do this and finally, do that. It is simply a list of operations.

In most programming languages this is done by putting the statements in order, separated by semicolons.

The next concepts is if statements. A classic example is the sexist inclusion in a program to get up and go to work.

if married less than five years
kiss wife

In other words, the state of the world is tested. If it is one condition, a particular item will be done. Otherwise, do something else --or nothing at all.

The third example is looping. An example might be as below. It is program to cook a Thanksgiving turkey.

check turkey
while (turkey not cooked)
wait five minutes
check turkey
end

We use loops for such tasks as summing a bunch of numbers or monitoring a nuclear reactor continuously.

Different programming languages support different actions. PASCAL supports operations analagous to those one might do on a calculator with memory. Various numbers are added, subtracted, multiplied, etc. and then put in different boxes. Those boxes are called variables. After a number is put in a variable, a statement can refer to that number by the variable name. Thus, the result of one computation can be used in another.

A programming language for a car-painting robot will have actions that will bend its arm, activate its sprayer, etc.

We will introduce each of the three ideas (sequencing, if statements, do loops) by assuming that the actions allowed move a car along a map that I provide. There are four actions allowed which are given by the statements below:

move one block east;
move one block west;
move one block north;
move one block south;

Note that one can't change the "one" to some other number. If you wanted to move two blocks east, you would have to write two statements as follows:

move one block east;
move one block east;

(When we learn about looping, we will see how to do something like moving one hundred blocks to the east without writing a hundred statements.)

But before we discuss this, I will