Reference

Appendix C: Common Errors and What They Mean

Every error here is one you're actually likely to hit while working through this book, most of them on purpose, in the chapter where they're first taught. This appendix is for coming back to later, once the specific memory of "oh right, chapter 8 talked about this" has faded.

Each entry follows the same shape: what QF Code is telling you, what probably caused it, a small broken example, and the fix.


"Loop exceeded maximum iterations"

What it means: A while or for loop ran 10,000 times without stopping, and QF Code halted it for you before it could freeze the browser tab.

Likely cause: The loop's condition never became false, usually because something inside the loop that should move it toward stopping isn't actually doing that.

QF Code example 1
var x = 1
while x > 0
    writeln(x)
    x = x + 1   // x keeps growing, x > 0 is never false
end while

Fix: Check that whatever the condition depends on is actually moving toward the stopping point on every pass.

QF Code example 2
var x = 1
while x <= 5
    writeln(x)
    x = x + 1
end while

See chapter 4.


"3" + 4 raises an error instead of a result

What it means: You tried to add a number-looking string directly to an actual number, and QF Code refused to guess whether you meant arithmetic or concatenation.

QF Code example 3
writeln("3" + 4)   // error

Fix: Say what you mean, explicitly, with num() or str().

QF Code example 4
writeln("3" + num("4"))   // 7
writeln("3" + str(4))     // "34"

See chapter 2.


num() raises an error on text that isn't a number

What it means: num() tried to convert a string to a number, and the string didn't look like one, "abc" has no reasonable numeric meaning.

QF Code example 5
var age = num(input("Age: "))   // crashes if the player types "abc"

Fix: Wrap the conversion in an attempt block, and ask again if it fails, instead of letting it crash the program.

QF Code example 6
attempt
    var age = num(input("Age: "))
error
    writeln("That doesn't look like a number.")
end attempt

See chapter 10.


Comparing a number to a string with <, >, <=, or >=

What it means: Relational comparisons require both sides to be the same type. Comparing a number directly to a string, even one that looks numeric, is an error, not an automatic conversion.

QF Code example 7
if age >= "13" then   // error, age is a number, "13" is a string

Fix: Convert one side so both are the same type.

QF Code example 8
if age >= num("13") then

See chapter 3.


Reassigning a constant

What it means: You tried to assign a new value to a name declared with const. Constants protect the binding itself, permanently, once it's set.

QF Code example 9
const maxAttempts = 3
maxAttempts = 5   // error

Fix: If a value genuinely needs to change later, it was never a constant to begin with, use var instead. If it shouldn't change, leave the constant as is and store the new value somewhere else.

See chapters 2 and 11. Note: a constant holding an array is a partial exception, the array's contents can still be changed with append(), insert(), or remove(), even though the constant name itself can never point to a different array.


Array index out of range

What it means: You tried to read or assign an array position that doesn't exist, an index below 0, or at or beyond the array's length.

QF Code example 10
var items = ["torch", "rope"]
writeln(items[5])   // error, only indexes 0 and 1 exist

Fix: Remember arrays start at index 0, and the last valid index is always length(array) - 1. Check length() before trusting an index that came from somewhere dynamic, like player input.

See chapter 5.


Wrong number of arguments in a function call

What it means: A function call didn't supply exactly the number of arguments the function declares as parameters.

QF Code example 11
function greet(name)
    writeln("Welcome, " + name + ".")
end function

greet()             // error, greet expects exactly one argument
greet("Alice", "!") // error, greet expects exactly one argument

Fix: Match the call to the declaration, exactly.

QF Code example 12
greet("Alice")

See chapter 6.


A logical operator given something other than a boolean, 0, or 1

What it means: and, or, xor, and not only accept actual booleans, or the numbers 0 and 1. Unlike some other languages, QF Code won't treat a string, an array, or empty as a stand-in for true or false.

QF Code example 13
if hasKey and "yes" then   // error, "yes" isn't a boolean

Fix: Use an actual comparison to produce a real boolean first.

QF Code example 14
if hasKey and answer == "yes" then

See chapter 3.


sqrt() of a negative number

What it means: sqrt() doesn't accept negative numbers, there's no real result to return.

QF Code example 15
sqrt(-9)   // error

Fix: Check the number is zero or positive before calling sqrt() on it, usually with a plain if.

See chapter 8.


Reserved word used as a variable name

What it means: You tried to declare a variable, constant, or function using a name that QF Code has already claimed as a keyword, attempt, match, function, and every other word in Appendix B, along with a handful reserved for future use.

QF Code example 16
var attempt = 0   // error, attempt is reserved

Fix: Pick a different name. tries, attemptCount, or guessNumber all work fine, since none of them are reserved words themselves.

See Appendix B for the full list of words this applies to.


Recursion depth exceeded

What it means: A function called itself more than 500 times deep without stopping, and QF Code halted it, the same protective instinct as the loop iteration limit, just measuring nested function calls instead of loop passes.

QF Code example 17
function countUp(n)
    writeln(n)
    countUp(n + 1)   // never stops, no base case
end function

countUp(1)

Fix: Every recursive function needs a base case, a condition that stops it from calling itself again.

QF Code example 18
function countUp(n)
    if n > 10 then
        return
    end if
    writeln(n)
    countUp(n + 1)
end function

See chapter 13.


Copyright © 2026 Edison Mooers. Published by Gibidda Press. Free for personal learning and qualifying noncommercial educational use. Commercial training, organizational use, redistribution, and adaptation require written permission. Full use terms.