pat, I removed the dim line from your code and moved the $a = $ = 1 up a bit and got 80:
Code:

Function A($)
Do
Do
$a=$a + $ mod 10 * ($ mod 10)
$=$/10
Until $=0
$=$a
$A=$=1
Until $<5
EndFunction



$=1 you know, it's evaluation.
$=1 returns true (or 1) if $ equals 1. otherwise it returns false (or 0).

thus $A = $ = 1 resets $A to zero always except when $A should return 1 (happy number).
_________________________
!

download KiXnet