?DIVISION BY ZERO ERROR
Commodore VIC-20
Severity: MinorWhat Does This Error Mean?
?DIVISION BY ZERO ERROR means the program tried to divide by zero, which is mathematically undefined. Commodore BASIC V2 halts immediately. Add an IF check before any division where the denominator could be zero.
Affected Models
- Commodore VIC-20
Common Causes
- Hard-coded division by zero: PRINT 10/0
- A variable used as divisor that was entered as zero via INPUT
- A loop counter that reaches zero used in a division
- A formula where an intermediate result evaluates to zero
How to Fix It
-
Find the division on the reported line number.
The error message includes the line. Type LIST <line number> to view it. Look for a / operator where the right-hand side could be zero.
-
Add an IF check before the division.
Safe division pattern: 80 IF B = 0 THEN PRINT "DIVIDE BY ZERO" : GOTO 10 90 PRINT A / B This skips or loops back when B is zero.
-
Validate user input that feeds into a divisor.
10 INPUT "ENTER VALUE"; B 20 IF B = 0 THEN PRINT "MUST BE NON-ZERO" : GOTO 10 30 PRINT A/B This keeps asking until the user enters a valid non-zero value.
-
Trace any formula where zero could appear as an intermediate result.
A complex expression like A / (B - C) causes ?DIVISION BY ZERO if B equals C. Add: IF B = C THEN <handle error> before the calculation.
Frequently Asked Questions
Does the VIC-20 return infinity for division by zero like some modern languages?
No. Commodore BASIC V2 halts with ?DIVISION BY ZERO ERROR — it does not return infinity, NaN, or any other sentinel value. You must prevent it explicitly with an IF check.
Is this the same as the C64 division by zero error?
Yes. The VIC-20 and C64 both use Commodore BASIC V2 — the error message, cause, and fix are identical on both machines.