Ad Space — Top Banner

Subscript Out of Range

Apple Apple II

Severity: Minor

What Does This Error Mean?

Subscript Out of Range means your program tried to access an array element beyond the array's declared size. In Applesoft BASIC, arrays default to 11 elements (0–10) unless you DIM them larger.

Affected Models

  • Apple II
  • Apple II Plus
  • Apple IIe
  • Apple IIc
  • Apple IIgs

Common Causes

  • Array index exceeds the DIM size
  • Array not DIMensioned at all — defaulting to 10 elements but program uses more
  • Loop counter going one step too far in a FOR loop that fills an array
  • Off-by-one error in array index calculation

How to Fix It

  1. Check your DIM statement.

    DIM A(20) creates 21 elements: A(0) through A(20). If your program accesses A(21) or higher, you get Subscript Out of Range.

  2. Remember Applesoft arrays default to 11 elements.

    If you use an array without DIM, you get A(0) to A(10) — 11 elements. Accessing A(11) crashes. Always DIM your arrays explicitly.

  3. Check your FOR loop upper limit.

    FOR I=1 TO 21 accessing A(I) when DIM A(20) — crashes on the last iteration. Change the loop to FOR I=1 TO 20, or DIM A(21).

  4. Add a bounds check in your code.

    Before accessing an array: IF I > 20 THEN ... to prevent the error and handle it gracefully.

Frequently Asked Questions

Why do Applesoft arrays start at index 0?

Applesoft follows the convention of most BASIC dialects of the era — arrays run from 0 to N, giving N+1 elements. Some programmers found this confusing and simply wasted element 0, starting their loops at 1.