Programmed Canon Canola calculators in 1977. Assorted platforms and languages ever since. Assisting with HOPL.info.
I am NOT looking for work -- I've got more than enough to do.
Location
Perth, WA Australia
Education
A few diplomas.
Work
Software Engineer at [Daisy Digital](https://daisydigital.com.au/)
Inside that for/next there's an if hidden away in the calculation.
Many dialects of BASIC do not have a boolean type but rather use the values 0 and -1 to signify false and true.
In the equation above the n %% i = 0 takes n modulus i and tests the result against 0. If true, -1 otherwise 0. The next level up in the formula therefore multiplies i by either -1 or 0 resulting in either -(i) or zero. The next level up subtracts a negative or subtracts a zero. According to standard number theory, subtracting a minus value is the same as adding a positive.
Were one to use if/then here it would convert
sum=sum-(i*(n%%i=0))
to
ifn%%i=0thensum=sum+iendif
In tbas's case, the formulaic approach is faster than the if/then. YMMV.
I think you forgot one. I'm not sure what to call it. Perhaps "calculated". The language is this case is tbas, a dialect of BASIC.
Inside that
for/next
there's anif
hidden away in the calculation.Many dialects of BASIC do not have a
boolean
type but rather use the values0
and-1
to signifyfalse
andtrue
.In the equation above the
n %% i = 0
takesn
modulusi
and tests the result against0
. If true,-1
otherwise0
. The next level up in the formula therefore multipliesi
by either-1
or0
resulting in either-(i)
orzero
. The next level up subtracts a negative or subtracts a zero. According to standard number theory, subtracting a minus value is the same as adding a positive.Were one to use
if/then
here it would convertto
In tbas's case, the formulaic approach is faster than the
if/then
. YMMV.To be fair I didn't try to least them all (if it's even possible, how to guarantee the exhaustiveness of list). Nice to have more examples