Sequencing
The organization of the sequence of a program is critical. Programs can be designed and structured in many different ways but if the sequence of the program operations is not maintained, the program will not perform the appropriate actions.
Consider the following programming steps. These are written in English and provided as comments in a Java format but they could be the English or pseudocode statements in any program.
// acquire three coefficients of a quadratic expression from a user
// calculate the two roots
// display the two roots
This program must be implemented in the order shown. You cannot calculate the two roots if you don’t have access to the three coefficients, and you cannot display the resulting roots until you have both acquired three coefficients and calculated the roots (in that order only).
Now consider the following.
// acquire money from a user
// acquire the soda selection from the user
// move the selected soda to the user tray (vend the product)
// provide change to the user as needed
Watch the video on this concept.
Again, these actions are almost always required to be conducted in order. You could provide change to the user before vending the soda, but you cannot vend the soda until you know what the user wants; in addition, your vending machine business will be very short lived if you don’t acquire the money before vending the product.
Now consider the following Java programming steps. You don’t need to know anything about programming to understand what this code accomplishes
// for first line
printSpace();
printSpace();
printAsterisk();
printEndLine();
// for second line
printSpace();
printAsterisk();
printAsterisk();
printAsterisk();
printEndLine();
// for third line
printAsterisk();
printAsterisk();
printAsterisk();
printAsterisk();
printAsterisk();
printEndLine();
Watch the video on this activity.
The code prints two spaces, then an asterisk, then it ends the line. Then it prints one space, then three asterisks, then it ends the line. Finally, it prints five asterisks and ends the line. Draw a small picture of this to see what the result would be. You could also open up a text editor such as Notepad and by following the instructions, you will see the result.
You might also find yourself controlling a robot’s movements. Consider the following program code.
moveOneSpace();
moveOneSpace();
moveOneSpace();
turnRight();
moveOneSpace();
moveOneSpace();
moveOneSpace();
turnRight();
moveOneSpace();
moveOneSpace();
moveOneSpace();
turnRight();
moveOneSpace();
moveOneSpace();
Watch the video on this activity.
You can try this on a spreadsheet. Place your cursor at a cell in the spreadsheet, then just follow the instructions. You will be able to see the path you have taken when you are done.
Again, you didn’t need to know anything about program code to know what to do as you followed these instructions. However, the instructions did need to be executed in a certain order to accomplish the given tasks.
Programming never needs to be difficult. However, it is critical that you specify exactly what you want to have happen, in exactly the order you want it to happen.