Computational Thinking and Simple Coding

Foundation

Coding writes step-by-step instructions for computers, and an algorithm is simply a clear set of steps to solve a problem. Programs are built from sequence, loops and conditions, with debugging when things go wrong; block-based tools such as Scratch let you create animations and games by dragging blocks. Recipes, routes and robot vacuums — algorithms are everywhere.

For:Primary 5 General Studies · Unit:Science & technology · Lesson 21 of 26 in the learning path

After this lesson, you can:
  • An algorithm is a clear set of steps; computer instructions must be precise and ordered.
  • Three structures: sequence runs in order, loops repeat actions, conditions choose by situation.
  • Program errors are bugs; debug step by step and test after every small piece.
文體:科技科普說明文有聲朗讀

文體小知識:編程科普說明文用生活例子解釋演算法、順序、循環和條件,令編程思維觸類旁通。

常識General Studies

§Text Passage

1Computers do not think; they follow instructions faithfully, so instructions must be clear and ordered. An algorithm is a step-by-step method of solving a problem — a recipe is a fine example. To make a peanut-butter sandwich: one, take two slices of bread; two, spread the peanut butter; three, add the lettuce; four, done. Change the order and the result changes; leave an instruction vague — just 'make a sandwich' — and the computer is lost. Breaking a task into clear small steps is the first lesson of computational thinking.

2Programs have three basic structures. Sequence runs instructions one after another. Loops write repeated actions once: 'repeat 4 times { move 100 steps; turn right 90 degrees }' draws a square without eight lines of commands. Conditions let a program choose: 'if it rains, take the umbrella; otherwise wear a cap.' A robot vacuum uses all three: 'repeat { go forward; if you hit a wall, turn }' — so it never keeps crashing and still cleans every room.

3Programs go wrong all the time; an error is called a bug, and finding and fixing it is debugging. Debug like a detective, testing step by step: a robot meant to walk a square back to its start stops after three sides — checking line by line shows the loop count is three instead of four; fix it and the program runs. Test after every small piece you write, and errors are easy to trace — a programmer's good habit.

4Primary students can begin with block-based tools such as Scratch, dragging blocks instead of typing: 'when the green flag is clicked' is an event block, 'move 10 steps' a motion block, and 'repeat' and 'if...else' control blocks — snapped together into greeting-card animations and maze games. Coding is everywhere: navigation apps time every route and suggest the fastest, search engines rank the most relevant results first, video platforms recommend shows by your taste — algorithms all. Decompose problems, find patterns, design steps, test and improve — this thinking serves every subject.

1Summary 重點摘要

Coding writes step-by-step instructions for computers, and an algorithm is simply a clear set of steps to solve a problem. Programs are built from sequence, loops and conditions, with debugging when things go wrong; block-based tools such as Scratch let you create animations and games by dragging blocks. Recipes, routes and robot vacuums — algorithms are everywhere.

2Vocabulary cards Vocabulary

A
Algorithm演算法

A clear set of steps to solve a problem, such as a recipe or route planner.

P
Program程式

A series of instructions written for a computer to execute.

S
Sequence順序

The program structure where instructions run one after another in order.

L
Loop循環

The structure repeating a block of instructions, such as 'repeat 10 times'.

C
Condition條件判斷

The 'if...then...else' structure letting a program choose by situation.

D
Debugging除錯

Finding and fixing wrong instructions in a program.

B
Block-based programming圖形化編程

Coding by dragging blocks instead of typing, as in Scratch.

C
Computational thinking編程思維

Thinking that decomposes problems, finds patterns, designs steps, tests and improves.

I
Instruction指令

A single step commanding the computer, which must be precise and clear.

3Step by step Steps

  1. Step 1: Turn a task into an algorithmExample: teaching a robot to make a sandwich needs precise, ordered commands — write 'take two slices of bread' first, then 'spread the peanut butter', then 'put the slices together'; just saying 'make a sandwich' leaves it helpless. Breaking a task into clear step-by-step instructions like this is called an algorithm. Writing algorithms trains us to think a problem through and solve it in an orderly way.
  2. Step 2: Simplify repeats with loopsExample: to make a robot draw a square, write 'repeat 4 times { move 100 steps; turn right 90 degrees }' — two lines of commands replace eight repeated ones. To change the size of the square, change one number instead of rewriting everything. Loops make programs shorter, easier to read and less prone to mistakes — the basic tool for handling repetitive tasks in coding.
  3. Step 3: Handle changes with conditionsExample: a robot vacuum runs the program 'repeat { move forward; if you hit a wall, turn right 90 degrees }', so it never crashes on endlessly and can clean the whole flat. Conditions let a program react differently to different situations: turning when obstacles appear, returning to the charger when the battery is low. With conditions, a program changes from a rigid routine into a helpful, flexible assistant.
  4. Step 4: Combine the three structuresExample: a maze program can wrap the sequential command 'move one square' inside 'repeat forever', and add two conditions — 'if a red wall is ahead, back up and turn right' and 'if you reach the goal, stop'. Sequence, loops and conditions are the three basic structures of a program, and combining them creates complex behaviour. Mastering how to combine them is mastering the skeleton of programming.
  5. Step 5: Test step by step to find the bugExample: the robot draws only three sides of the square and stops; checking the commands piece by piece shows the loop count is 3 instead of 4, and after the fix the program runs properly. Finding and correcting program errors is called debugging, and the errors are nicknamed bugs. Debugging takes patience: change one thing at a time and test step by step, so the problem can be pinpointed — programmers live with bugs every day.
  6. Step 6: Create with ScratchExample: in Scratch, snap 'when green flag clicked' onto 'repeat 10 times { move 10 steps; play sound }', and the sprite walks while making sounds. Scratch lets beginners write programs by dragging colourful blocks, with no typing needed. Pupils can start with simple animations, add conditions and variables bit by bit, and build little interactive games — learning while playing.
  7. Step 7: Spot algorithms in lifeExample: a navigation app compares the expected travel time of every route and suggests the fastest one; a search engine ranks the most relevant results first; a streaming platform recommends shows by viewing history. Behind these thoughtful services are algorithms. Learning to recognise the coding in daily life helps us understand how technology decides what we see, and use these tools more consciously.

4Diagrams Diagrams

流程圖符號:四種磚頭 Flowchart symbols開始/結束處理 process判斷?輸入輸出圓角方形菱形平行四邊形例:計平均分流程開始 → 輸入三科分數 → 相加÷3(處理)→ 顯示結果 → 結束規矩:箭嘴表示行嘅次序;判斷菱形一定要有兩條出路(是/否)畫流程圖=諗清楚先寫 code——程式設計師嘅草稿
Fig. 1: Flowchart symbols

5Worked example Example

Example: Yan must design the movement program for a maze game: the sprite keeps moving forward, backs up one square and turns right whenever it meets a red wall, until it reaches the goal. Write the algorithm in words using sequence, loops and conditions.

  1. Event: when the 'start' button is pressed, the program begins.
  2. Outer loop: wrap the following steps in 'repeat forever' so the sprite keeps moving.
  3. Sequence: move forward one square.
  4. Condition one: 'if a red wall is ahead, back up one square and turn right 90 degrees; otherwise keep going'.
  5. Condition two: 'if you reach the goal square, stop the program and play the victory sound'. With the three structures combined, the sprite finishes the maze automatically.
  6. Answer: The algorithm = an event to start + an outer loop + the sequential 'move one square' + two conditions ('back up and turn at red walls' and 'stop at the goal') — and the sprite completes the maze on its own.

6Common mistakes Mistakes

✗ Believing coding requires memorising heaps of English words
✓ Block-based coding replaces typing with dragged blocks; clear logic matters, not vocabulary
✗ Writing ten identical lines for an action repeated ten times
✓ Use a loop — 'repeat 10 times' — for compact, easily changed code
✗ Deleting everything and rewriting when the program fails
✓ Test step by step to find the faulty line (debug) — often only one number needs changing
✗ Forgetting the 'else' part of a condition
✓ 'If it rains take the umbrella, otherwise wear a cap' — think through both cases
✗ Writing vague instructions such as 'draw a flower'
✓ Computers need precision: repeat 6 times { move 100 steps; turn right 60 degrees } draws a hexagon shape

7Quick check Quick check

Q1What is an algorithm?

Q2What are the three basic structures of a program?

Q3What is debugging?

Q4What is the advantage of using a loop for 'skip ten times'?

Q5Give two everyday examples of algorithms.

8Recap Recap

  • An algorithm is a clear set of steps; computer instructions must be precise and ordered.
  • Three structures: sequence runs in order, loops repeat actions, conditions choose by situation.
  • Program errors are bugs; debug step by step and test after every small piece.
  • Block-based tools like Scratch let primary students create animations and games by dragging blocks.
  • Navigation, search and recommendations all run on algorithms — computational thinking serves every subject.

Other subjects in this grade

Same subject, other grades