Imagine you are following a recipe to bake a cake. If the recipe is written in a language you don’t understand, or if it has missing steps, you won’t even be able to start. This is how programming errors work! According to the sources, there are three main types of mistakes you will encounter:
- Syntax Errors: The “Language Rule” Breakers A syntax error happens when you don’t follow the “grammar” rules of the programming language.
- What happens: The program refuses to start. The compiler or interpreter simply cannot understand what you wrote.
- Examples: You might misspell a command like writing OUTPT instead of OUTPUT, or forget to put a closing bracket ) or quotation marks.
- The Fix: Read the error messages provided by your computer—they usually tell you exactly where you went wrong.
- Logic Errors: The “Wrong Results” Mistakes A logic error is tricky because the program actually runs without crashing, but it gives you the wrong answer. It’s like following a recipe perfectly, but the recipe itself was wrong, so you end up with a salty cake instead of a sweet one.
- What happens: The program runs, but the output is incorrect.
- Examples: Using a > (greater than) sign when you meant to use >= (greater than or equal to), or using a wrong formula for a calculation.
- The Fix: You need to do a “dry run” using a trace table. This means you follow the code step-by-step with a pen and paper to see where the math or logic went sideways.
- Runtime Errors: The “Sudden Crashes” A runtime error occurs while the program is already running, causing it to suddenly stop or “crash”.
- What happens: The program starts fine, but then it hits a problem it can’t handle and just quits.
- Examples: Trying to divide a number by zero or trying to find a file on the computer that doesn’t exist.
- The Fix: You must add “validation checks” to make sure the data coming into the program is correct before the program tries to use it.
