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.

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 ShapeNameDescription
Flowchart flowline.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.
Flowchart terminal.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”.
Flowchart process.Process boxRepresents a set of operations that changes value, form, or location of data. Represented as a rectangle.
Flowchart decision.DecisionShows 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).
Flowchart input/output.Input/OutputIndicates the process of inputting and outputting data, as in entering data or displaying results. Represented as a rhomboid.
loadingSubroutineUsed to CALL a Subroutine from the main flowchart.
loadingConnectorUsed to indicate the continuation of a flowchart on another page.
Adapted from Wikipedia [3]

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):

A flowchart for the algorithm that outputs numbers starting at 1 and ending at 10.

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
A flowchart for the algorithm that outputs numbers starting at 1 and ending with the number input at runtime.
A flowchart for the algorithm that outputs numbers starting at 1 and ending with a number input at runtime.

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:

  1. Continue to a more advanced algorithm in the Advanced algorithm tutorial
  2. Choose a language and write your program; head on over to the tutorials:

References:

  1. Programiz (no date) What is an Algorithm? Available at: https://www.programiz.com/dsa/algorithm (Accessed: 24 February 2024).
  2. Indicative (2021) What Is A Programming Algorithm? Available at: https://www.indicative.com/resource/programming-algorithm/. (Accessed: 24 February 2024).
  3. Wikipedia (no date) Flowchart. Available at: https://en.wikipedia.org/wiki/Flowchart (Accessed: 15 March 2023).

By MisterFoxOnline

Mister Fox AKA @MisterFoxOnline is an ICT, IT and CAT Teacher. He has a passion for technology and loves to find solutions to problems using the skills he has learned in the course of his IT career.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.