When teaching programming, it is important to consider whether a student is battling with computational thinking or the syntax of a language.
Learning a programming language is difficult. Trying to learn the syntax and structure of a programming language should only be tackled once a student has a basic outline of the process of planning and writing software. Students must be encouraged to verbally break down a problem into steps and then write out pseudo-code and create flowcharts to visualise their solutions. Only once the program has been designed should they start writing actual code in a programming language.
In this tutorial:
See also:
1. Have a laugh
2. Algorithm
In the tutorial Pseudo-code: teaching programming I demonstrated the process of verbalising and then documenting the process of writing a program in pseudo-code.
In computer programming, an algorithm is a set of well-defined instructions to solve a particular problem. [1]
A programming algorithm is a procedure or formula used for solving a problem. It is based on conducting a sequence of specified actions in which these actions describe how to do something, and your computer will do it exactly that way every time. [2]
This process may seem extremely difficult at first. The good news is that like most things this is a skill that can be practiced. You will also find that the basic patterns for solving problems are actually very similar and you will soon learn when and where to use which one!
3. Pseudo-code
Pseudo-code is simply an implementation of an algorithm.
- It is written in plain English and does not have syntax like any of the programming languages.
- Pseudo-code can’t be compiled or interpreted by the computer. It cannot be run.
- Pseudo-code acts as a bridge between your algorithm or flowchart and your final program in a computer language. It can also form the basis of your documentation.
You will need the following actions — some of which are familiar from Maths as well as from using Excel and Access — to write your pseudo-code:
- Inputting data: INPUT or READ
- Outputting data: WRITE or PRINT
- Assignment operator: ←
- Comparison operators: < (less than), > (greater than), = (equal to), <> (not equal to)
- Mathematical operators: + (add), – (subtract), * (multiply), / (divide)
- Comments: // this is a comment
You will also use variables in your pseudo-code (and your flowcharts). A variable is a placeholder for a value that can change when the program runs.
The following example of pseudo-code is for a program that will output the numbers 1 to 10:
counter ← 0 // assign the value zero to a variable named counter WHILE counter < 10 counter ← counter + 1 // increment the counter variable PRINT counter // output the value currently in the counter variable ENDWHILE
4. Flowchart
An algorithm can be expressed visually as a flowchart. The steps in the process being described are represented by a set of symbols and the flow of the data or direction of the process is represented by arrows called flowlines.
The following symbols are standard:
ANSI/ISO Shape | Name | Description |
---|---|---|
Flowline (Arrowhead) | Shows the process’s order of operation. A line coming from one symbol and pointing at another. Arrowheads are added if the flow is not the standard top-to-bottom, left-to-right. | |
Terminator (Start/Stop) | Indicates the beginning and ending of a program or sub-process. Represented as a stadium, oval or rounded (fillet) rectangle. They usually contain the word “Start” or “End”, or another phrase signalling the start or end of a process, such as “submit inquiry” or “receive product”. | |
Process box | Represents a set of operations that changes value, form, or location of data. Represented as a rectangle. | |
Decision | Shows a conditional operation that determines which one of the two paths the program will take. The operation is commonly a yes/no question or true/false test. Represented as a diamond (rhombus). | |
Input/Output | Indicates the process of inputting and outputting data, as in entering data or displaying results. Represented as a rhomboid. | |
loading | Subroutine | Used to CALL a Subroutine from the main flowchart. |
loading | Connector | Used to indicate the continuation of a flowchart on another page. |
Microsoft PowerPoint has a section in its Shapes feature on the Insert ribbon for Flowchart shapes and connectors. See the tutorial Creating a flowchart in PowerPoint.
Below is a flowchart for the pseudo-code example listed above (created with PowerPoint):
5. Version 2
The following example of pseudo-code is an enhancement of the first version. This version will output numbers starting at 1 and ending at a value input by the user at runtime:
counter ← 0 // assign the value zero to a variable named counter INPUT max // assign the value input at runtime to a variable named max WHILE counter < max counter ← counter + 1 // increment the counter variable PRINT counter // output the value currently in the count variable ENDWHILE
6. Next steps
In my opinion, learning to write pseudo-code and create flowcharts is much easier if you take it one step further and implement your planning using Scratch or LOGO.
So, for example, the final pseudo-code listed in Step 5 above would be written in LOGO BASIC as follows (copy & paste the code into the Turtle Academy Playground):
;clear previous output cleartext ;assign the value zero to a variable named counter make "counter 0 ;assign the value provided at runtime to a variable named maxNumber make "maxNumber (readword [ Enter the maximum value: ] ) repeat :maxNumber [ make "counter :counter +1 print :counter ]
You can choose one of two paths now:
- Continue to a more advanced algorithm in the Advanced algorithm tutorial
- Choose a language and write your program; head on over to the tutorials:
References:
- Programiz (no date) What is an Algorithm? Available at: https://www.programiz.com/dsa/algorithm (Accessed: 24 February 2024).
- Indicative (2021) What Is A Programming Algorithm? Available at: https://www.indicative.com/resource/programming-algorithm/. (Accessed: 24 February 2024).
- Wikipedia (no date) Flowchart. Available at: https://en.wikipedia.org/wiki/Flowchart (Accessed: 15 March 2023).