GCSE · Computer Science · OCR · Spec J277

Syntax errors

One wrong letter. That's all it takes for a whole program to refuse to start. Let's see exactly what happens, and how to fix it fast.

Computer Science · Programming

Press Run and watch what doesn't happen

Attempt 1 has one typo on line 4. Attempt 2 is the same program after the fix. Step through both and keep an eye on the Output box.

Lines 2 and 3 are perfectly fine. Will 'Starting...' get printed before the typo on line 4 causes trouble? Decide, then step.

1 # Attempt 1
2 print("Starting...")
3 name = "Sam"
4 iff name == "Sam":
5 print("Hi Sam!")
6 # Attempt 2: after the fix
7 print("Starting...")
8 name = "Sam"
9 if name == "Sam":
10 print("Hi Sam!")

Variables

Output

 

Step 1: You press Run on Attempt 1. Made your prediction? Keep your eyes on the Output box and the Variables panel.

1 / 9

Use Next to step. Steps 1 to 4 are Attempt 1, step 5 is the fix, and Attempt 2 runs from step 6.

Step 1 of 9: You press Run on Attempt 1. Made your prediction? Keep your eyes on the Output box and the Variables panel..

Watch out: The program doesn't run up to the bad line and then stop. It doesn't skip the bad line either. With a syntax error, nothing runs at all.

Your turn

Find the slip before the translator does

This program won't run: the translator has flagged a syntax error. Which line breaks the rules?

A program with one typing slip — which line goes wrong?

Syntax error or logic error?

Syntax errorvsLogic error

Start with the top row. It settles most cases on its own.

Focus

Does the program run?

Syntax error

No. It won't run at all.

Logic error

Yes, it runs.

The insight

This is the quickest test. A program that runs can't have a syntax error in it.

What's gone wrong?

Syntax error

The code breaks the rules of the programming language.

Logic error

The program doesn't return the result you expected.

Who catches it?

Syntax error

The translator flags it, and most IDEs highlight it when you try to run.

Logic error

It isn't flagged. The IDE can't pick it up.

How easy is it to detect?

Syntax error

Easier, because it gets flagged for you.

Logic error

Typically more difficult, because nothing points to it.

Diagnose it

Which kind of error is it?

Pick a situation, then choose syntax error or logic error.

Still to sort

Syntax error (0)

The language's rules are broken, so it won't run.

Where the line is: If the program ran at all, it isn't this.

Logic error (0)

It runs, but the result isn't what you expected.

Where the line is: If the translator flagged it, it isn't this.

6 of 6 still to sort.

Six things that went wrong. Put each one where it belongs.

Debugging

Put the debugging steps in order

The order you carry out each step when debugging during development

1 · First step5 · Last step
  1. Fix the error

  2. Read the error message

  3. Run the code to check that the update works

  4. Find the error

  5. Trace through the code to detect where the error occurs

Watch out: Fixing is not the last step. Until you run the code again, you don't know the fix worked.

WHAT YOU'VE LEARNED

A quick recap of today's lesson.

Break the language's rules and the program won't even start. Here's how to spot the slip and fix it.

What you need to know

  • A syntax error happens when your code breaks the rules of the programming language.
  • The translator is what flags a syntax error.
  • A program with a syntax error won't run at all, not even the lines before the mistake.
  • Have a goYour mate's 100-line game has a misspelt keyword on line 99. "Relax," they say, "the first 98 lines will still run." Will they?

    No. Not one line runs.

    A misspelt keyword breaks the rules, so it's a syntax error. A program with a syntax error won't run at all, so line 99 holds up lines 1 to 98 as well.

  • Common causes are spelling or typing slips, such as a misspelt keyword or a missing bracket.
  • Most IDEs highlight syntax errors when you try to run your code.
  • A logic error is different: the program runs, but it doesn't give the result you expected.
  • Logic errors are typically harder to detect, because the IDE can't pick them up.
  • Have a goIf you had to choose, would you rather hunt for a syntax error or a logic error? Pick one, then say why.

    A syntax error.

    A syntax error gets flagged by the translator. A logic error lets the program run and the IDE can't pick it up, so you have to find it yourself.

  • Debugging is the process of finding and correcting errors in program code.
  • Start debugging by finding the error, reading the error message, then tracing through the code to see where it occurs.
  • Finish by fixing the error and running the code again to check the update works.
  • Have a goPriya spots her typo, fixes it, then shuts her laptop. "Done!" What has she skipped?

    Running the code again to check the fix works.

    The fix isn't proven until the program runs. Skipping the check means hoping the fix worked rather than knowing it did.

The big picture

A syntax error happens when code breaks the rules of the programming language. The translator flags it, and a program with a syntax error will not run at all. Common causes are spelling or typing slips, and most IDEs highlight syntax errors when you try to run your code. A logic error is different: the program runs but doesn't return the expected result, and because the IDE can't pick it up, it is typically harder to detect. Debugging means finding and correcting errors: find the error, read the error message, trace through the code to see where it occurs, fix it, then run the code to check the update works.

Key points

1Syntax error: the code breaks the rules of the programming language, and the translator flags it.
2A program with a syntax error will not run. No lines run, including the ones before the mistake.
3Spelling and typing errors are common causes. Most IDEs highlight syntax errors when you try to run your code.
4Logic error: the program runs but doesn't return the expected result. The IDE can't pick it up, so it's typically harder to detect.
5Debugging steps: find the error, read the error message, trace through the code to detect where it occurs, fix it, then run the code to check the update works.

Worked example

Problem

Leo presses Run on this three-line program and gets an error message instead of any output. Debug it. for lap in range(1, 4) print("Lap", lap) print("Race over!")

⚠ Watch out

Thinking a program with a syntax error will run up to the faulty line and then stop. It feels right, because you read code from the top down. But a program with a syntax error won't run at all, so even a perfect line 1 never runs.

🧠

Memory hook

Syntax error? It won't start. Logic error? It starts, but gets it wrong.

✓

Check yourself

A program has a mistyped keyword on its very last line. How much of it runs, what kind of error is it, what flags it, and how would you debug it?

Flashcards

(11)
What is a syntax error?
An error that happens when the rules of the programming language have not been followed.
What flags a syntax error?
The translator.
How much of a program runs if it contains a syntax error?
None of it. A program with a syntax error will not run.
Give the common causes of syntax errors.
Spelling or typing errors, for example a misspelt keyword or a missing bracket.
When do most IDEs highlight syntax errors?
When you try to run your code.
What is a logic error?
An error where the program runs but does not return the expected result.
Why are logic errors typically harder to detect than syntax errors?
The IDE cannot pick them up, because the program still runs.
What is debugging?
The process of finding and correcting errors in program code.
Once you've found an error, what do you do before tracing through the code?
Read the error message.
Why do you trace through the code when debugging?
To detect exactly where the error occurs.
What is the final step of debugging, and why?
Run the code again, to check that the fix actually works.

Tap any card to flip it, or use Study as deck to go through them one at a time. In the full lesson these run as a spaced-repetition deck — you rate each card Hard, Good or Easy and the tricky ones keep coming back until they stick.

Learning with Lightbulb is opening soon

You can use this lesson now. Join the waitlist and we'll let you know when the full Lightbulb experience is ready.

Keep me posted

More OCR GCSE Computer Science topics

See the full OCR Computer Science curriculum →

How this lesson was checked. This OCR GCSE Computer Science (specification J277)lesson was published through Lightbulb Learning's human-designed editorial process — the educational standards, accuracy rules and publication checks it must pass were authored and approved by Philip Halpin. It passed subject-specific assessment, automated educational checks and technical publication verification before going live (publication checks completed 3 November 2026). Published pages are monitored, human spot-checking is ongoing across the lesson library, and anything found wrong is corrected or withdrawn. How our lessons are made and checked. Spotted a mistake? Email hello@lightbulblearning.co and we'll review it.