Reference

The bug zoo

A bug isn’t a disaster — it’s a clue. Almost every mistake belongs to a small family you can learn to spot on sight. Here are the ones the lab drills; each has a character who always makes it. The trick is the same every time: compare what it prints to the goal, and the line that makes them differ is the culprit. Open the debug lab →

  • 🐞 Offby One short or one over

    A loop bound is off by one — ..< stops before the number, ... includes it.

    How to catch it: Check ..< vs ... and whether count should be count or count-1.

  • 🐞 Equals Saying vs asking

    = gives a value; == asks a question. An if needs ==.

    How to catch it: '=' assigns; '==' compares — an if/while condition needs '=='.

  • 🐞 Andor And vs or

    && is true only when both are true; || is true when either is.

    How to catch it: Swap '&&' and '||' to match what you meant.

  • 🐞 Range Reaches past the end

    A loop or index goes up to count, but positions stop at count-1.

    How to catch it: Use 0..<array.count (exclusive), not 0...array.count.

  • 🐞 Zero Divide by zero

    Dividing by 0 crashes — check the divisor first.

    How to catch it: Fatal error: Division by zero — test the denominator before /.

  • 🐞 Hush Wrong but it runs

    No crash, no red — the logic just does the wrong thing; a test catches it.

    How to catch it: Write a test with a known answer to reveal the wrong result.

  • 🐞 Forever Never stops

    The while test never becomes false, so the loop runs forever.

    How to catch it: Make sure something inside the loop moves the test toward false.

Fixing a bug and saying why in one sentence — the “bug report” — is a real coder’s skill. Every program here is written in a teaching subset of the Swift language. Catch a bug →