[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Looking for code samples using goto and labels
- From: Andres Perera <andres.p@...>
- Date: Sun, 24 Feb 2013 14:26:51 -0430
i forgot my example
here's an naive implementation for bcd.add() in lua which exhibits the
"whole function is a loop" symptom. this example i find it much more
clearer to be imperative than (co)recursive because i don't need to
parametrize for a loop control variable. also, the code is easily
mapped to C this way which is important to me because lua is just a
prototype language in this project
function add(x, y)
local c
local i
local t
local z
i = 1
z = {}
::a::
t = (x[i] or 0) + (y[i] or 0)
if c then
t = t + 1
c = false
end
if t >= 10 then
t = t - 10
c = true
end
z[i] = t
i = i + 1
if c or x[i] or y[i] then
goto a
end
return z
end