Re: static variable

new topic     » goto parent     » topic index » view thread      » older message » newer message

Another way of approaching this is through a recursion

in pseudo code

function fibonacci(int N) return int
if N <= 0 then
return 0
else if N = 1 then
return 1
else
return fib-helper(1,N,0)
end if
end

function fib-helper(int i, int N, int acc) return int
if i = N then
return acc + i
else
return fib-helper(i+1,N,acc+i)
end if
end


Static variables are probably best to avoid as their implementation is likely to be tricky (it's the fact that you go out of scope yet keep a link to that scope).

Recursion has its own problems. I don't know that Euphoria does tail-call elimination - it might.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu