?DIVISION BY ZERO ERROR
Apple Apple II
Severity: MinorWhat Does This Error Mean?
?DIVISION BY ZERO ERROR means your program tried to divide a number by zero. This is mathematically undefined, so BASIC stops the program. Add an IF check before the division to handle the zero case.
Affected Models
- Apple II
- Apple II Plus
- Apple IIe
- Apple IIc
- Apple IIGS
- AppleWin emulator
Common Causes
- Variable used as a divisor has the value zero
- User entered zero via INPUT and the program divides by it
- Counter variable reached zero in a loop before the division
- Uninitialised variable defaulting to zero used as a divisor
How to Fix It
-
Add an IF check before every division.
Before A = B / C, add: IF C = 0 THEN PRINT "CANNOT DIVIDE BY ZERO" : GOTO (safe line)
-
Validate INPUT values before using them as divisors.
After INPUT C, add: IF C = 0 THEN PRINT "PLEASE ENTER A NON-ZERO NUMBER" : GOTO (input line)
-
Check that loop counters do not reach zero before being used as divisors.
If a FOR loop counts down to 0, the last iteration uses 0 as the loop variable. Adjust the loop to stop at 1: FOR I = 10 TO 1 STEP -1
Frequently Asked Questions
Why can you not divide by zero?
Division by zero is mathematically undefined — there is no number that, multiplied by zero, gives a non-zero result. BASIC catches this and stops the program rather than producing a meaningless result.
Does this error ever happen in hardware or just in BASIC?
The Apple II's 6502 CPU does not have a hardware divide instruction, so all division is done in software by BASIC. BASIC checks for zero before dividing and produces this error if found.