ARTICLE CONTENTSOn this page 13 sections
Basic Algorithm for Creating Programs (Block Coding)
Performance Objectives
By the end of the lesson, students should be able to:
- describe flowcharts;
- state the importance of flowcharts in programming;
- interpret flowcharts;
- describe pseudocodes;
- state the benefits of pseudocodes;
- use pseudocodes to execute a task.
Introduction to Algorithms
An algorithm is a step-by-step set of instructions or rules followed to solve a problem or complete a task.
Before writing a computer program in any language, including block-based programming languages like Scratch, a programmer must first plan the steps to solve the problem. This plan is the algorithm. Algorithms can be represented in different ways so that humans can understand them easily before they are converted into computer code. The two most common tools used to represent algorithms are flowcharts and pseudocode.
Meaning of a Flowchart
A flowchart is a diagram that uses graphic symbols to show the step-by-step sequence of operations or steps in an algorithm.
Flowcharts use standard geometric shapes to represent different types of actions, and arrows to show the direction of the flow from one step to the next. This visual representation makes it easy to see how a program starts, processes information, makes decisions, and ends.
Flowchart Symbols and Meanings
Standard symbols are used internationally to design flowcharts. Each shape has a specific meaning and function in a program design.
The standard flowchart symbols include:
- Terminal Symbol (Oval): This shape represents the starting point or ending point of a flowchart. It contains the word “Start” or “Stop”.
- Input/Output Symbol (Parallelogram): This shape represents inputting data into the program or outputting results from the program. For example, reading a number or displaying a message.
- Processing Symbol (Rectangle): This shape represents an action, calculation, or process. For example, adding two numbers together or moving a character on a screen.
- Decision Symbol (Diamond): This shape represents a decision point where a question is asked. The answer to the question determines which path the program will follow. The paths are usually labelled “Yes” and “No”, or “True” and “False”.
- Flowlines (Arrows): These lines connect the symbols and show the direction of the process flow.
Importance of Flowcharts in Programming
Flowcharts are highly valuable tools for programmers and system designers.
The main benefits of using flowcharts in programming include:
- Easy Communication: Flowcharts provide a clear visual way to explain the logic of a program to other people, including non-programmers.
- Effective Analysis: A flowchart allows a programmer to analyse the problem more effectively, ensuring that no steps or logical possibilities are missed.
- Efficient Coding: Once a flowchart is drawn, it serves as a blueprint or guide that makes writing the actual program code much faster and easier.
- Systematic Debugging: Flowcharts help programmers locate errors or logical bugs in a program by tracing the flowlines step by step.
- Proper Documentation: Flowcharts serve as permanent records of how a program works, which is useful for future maintenance or updates.
Interpreting Flowcharts
Interpreting a flowchart means reading and understanding the logic of the algorithm by following the symbols and flowlines from the start to the end.
To interpret a flowchart correctly, a person must follow the direction of the arrows, perform the action described in each shape, and answer the questions in the decision diamonds to choose the correct path.
Worked Example 1: Flowchart for Making Tea
Making a cup of tea is a daily activity that can be described as an algorithm. The flowchart below shows the step-by-step process of making tea, including a decision point about adding sugar.
To interpret the tea-making flowchart, follow these steps:
- Start the process at the “Start” terminal.
- Move down to the first process box and boil the water.
- Move to the next process box and pour the hot water into a cup containing a tea bag.
- Reach the decision diamond and answer the question: “Want sugar?”.
- If the answer is “Yes”, follow the “Yes” arrow to the process box “Add sugar”, then proceed to “Stir tea”.
- If the answer is “No”, follow the “No” arrow directly to the process box “Stir tea”, skipping the sugar step.
- Move to the output box to serve the tea.
- End the process at the “Stop” terminal.
Worked Example 2: Flowchart for a Walking Animation
In block coding environments like Scratch, a walking animation is created by repeatedly moving a character (sprite) and changing its appearance (costume). The flowchart below shows the algorithm for a simple walking animation that repeats five times.
To interpret the walking animation flowchart, follow these steps:
- Start the program at the “Start” terminal.
- Set the step counter to 0 in the first process box.
- Reach the decision diamond to check if the count has reached 5.
- If the count is 5 (Yes), follow the arrow to “Stop” to end the animation.
- If the count is not 5 (No), follow the arrow to move the sprite forward by 10 steps.
- Change the sprite’s costume to the next costume to make it look like it is taking a step.
- Wait for 0.2 seconds so the animation does not run too fast.
- Add 1 to the count to record that one step has been completed.
- Follow the flowline back up to the decision diamond to check the count again.
Meaning of Pseudocode
Pseudocode is an informal, detailed description of a computer program or algorithm written in simple English rather than a programming language.
The word “pseudo” means false or imitation. Therefore, pseudocode is “imitation code”. It does not follow the strict grammatical rules (syntax) of any specific programming language, making it easy for humans to read and write. It uses structured English to outline the logic of the program before actual coding begins.
Benefits of Pseudocode
Pseudocode is widely used in software development because of its simplicity and structure.
The main benefits of pseudocode include:
- Simplicity: It is written in plain English, which means anyone with basic reading skills can understand the program logic.
- Language Independence: Pseudocode does not belong to any specific programming language. A programmer can write pseudocode once and then translate it into Scratch, Python, Java, or any other language.
- Quick Writing: It is faster to write than a flowchart because it does not require drawing shapes, and faster than actual code because it does not require correct programming syntax.
- Easy Modification: Changes can be made quickly by simply editing the text lines.
- Bridge to Code: It acts as an intermediate step that helps programmers transition smoothly from a mental idea to actual computer code.
Writing Pseudocode
When writing pseudocode, standard words are often used to represent programming structures. These words are usually written in capital letters to make the structure clear.
Common keywords used in pseudocode include:
- START / BEGIN: Marks the beginning of the algorithm.
- INPUT / READ: Gets information from the user or a sensor.
- OUTPUT / DISPLAY / PRINT: Shows information on the screen.
- IF / THEN / ELSE: Used for decisions and conditions.
- REPEAT / WHILE: Used for loops and repeating actions.
- END / STOP: Marks the end of the algorithm.
Worked Example 1: Pseudocode for Making Tea
The algorithm for making tea can be written in pseudocode as follows:
START
Boil water
Pour hot water into a cup with a tea bag
IF sugar is wanted THEN
Add sugar to the cup
ENDIF
Stir the tea
Serve the tea
END
Worked Example 2: Pseudocode for Walking Animation
The algorithm for the walking animation project can be written in pseudocode as follows:
START
Set count to 0
WHILE count is less than 5 DO
Move 10 steps
Switch to next costume
Wait 0.2 seconds
Add 1 to count
ENDWHILE
END
Designing a Flowchart and Writing Pseudocode (Practical Guide)
This section provides step-by-step instructions on how to design a flowchart and write pseudocode for a simple task.
How to Design a Flowchart
The procedure for designing a flowchart involves the following steps:
- Identify the starting point and ending point of the task.
- List all the inputs needed and the expected outputs.
- Write down the processing steps and decisions in the correct order.
- Draw the “Start” oval at the top of the page.
- Draw flowlines downwards and add the input, process, decision, and output shapes in sequence.
- Write the specific instruction inside each shape.
- Draw the “Stop” oval at the end of the sequence.
- Review the flowchart by tracing the paths with a finger to ensure the logic is correct.
How to Write Pseudocode
The procedure for writing pseudocode involves the following steps:
- Write “START” on the first line.
- Use simple English statements to describe each action.
- Indent lines inside decisions (IF-THEN) or loops (WHILE) to make the structure easy to read.
- Use capital letters for key control words like IF, THEN, ELSE, WHILE, and END.
- Write “END” on the final line.
Summary
Algorithms are essential planning tools in computer programming. Flowcharts provide a visual diagram of the algorithm using standard shapes like ovals, rectangles, parallelograms, and diamonds. Pseudocode provides a text-based, structured English description of the algorithm. Both tools help programmers design, analyze, and communicate program logic clearly before writing actual block code in environments like Scratch.
Questions for Evaluation
The following questions can be used to assess understanding of this unit:
- Define a flowchart.
- State three benefits of using a flowchart in programming.
- Identify the flowchart symbol represented by each of the following shapes:
- Oval
- Parallelogram
- Rectangle
- Diamond
- Describe pseudocode and state two of its benefits.
- Construct a flowchart for the process of washing hands.
- Write the pseudocode for a program that asks a user for their name, and then displays a welcome message saying “Hello” followed by their name.







0 comments
Open the discussion when you need it. Comments stay collapsed until requested so the initial article remains light.