Skip to main content
Informatik.uz
Chapter 1. Algorithm Basics

Finding and Fixing Errors in Algorithms

If an algorithm has a mistake, the executor gives a wrong result. We learn the kinds of errors and how to find them by testing by hand.

Topic 5 of 111 min readUpdated October 27, 2026
All topics (5 of 11)

Making mistakes while writing an algorithm is normal, and even experienced programmers do it. The executor carries out commands exactly and without thinking, so it will not fix a mistake by itself. Being able to notice and find an error is an important skill for a programmer.

There are two kinds of errors. A syntax error means a command is written incorrectly, or the executor does not know that command. A logic error means the commands are written correctly, but their order or number is wrong, so the result is not what was expected. For example, moving a robot 4 squares instead of 3 or forgetting a turn is a logic error.

The best way to find an error is to test the algorithm by hand. You pick a simple example and carry out the algorithm command by command, writing the values of the variables in a table after each step. The step where the result differs from the expected one points to the error.

Once you have found an error, fix it and test the algorithm again. It is better to fix only one error at a time, so you can see how the change affected the result. Finding errors is part of learning, so do not be upset by them.

Key takeaways

  • The executor follows commands without thinking and will not fix errors itself.
  • Errors are either syntax errors or logic errors.
  • Testing an algorithm by hand helps find errors.
  • Fix errors one at a time and test again each time.

Practice tasks

  1. This algorithm has a mistake: “1) Pour water into the kettle. 2) Add tea leaves. 3) Boil the kettle. 4) Brew the tea.” Find and fix it.
  2. A robot must go from (1; 1) to (3; 1). The algorithm is “forward, forward, forward”. Test it by hand and find the mistake.
  3. The algorithm for the average of two numbers is “S = a + b / 2”. Test it with a = 4, b = 8, then find and fix the mistake.

Review questions

Test yourself: think first, then reveal the answer.

  1. 1What is a logic error?
    The commands are written correctly, but their order or number is wrong, so the result differs from what was expected.
  2. 2Why test an algorithm by hand?
    To find the step where the result departs from the expected one and so locate the error.

0 of 11 topics completed

Sign in to mark
Informatika 6-sinf darsligi muqovasi
In the textbookInformatics — Grade 6