Can someone please explain this? I'm guessing I don't understand order of
execution.
When perusing >>fibonacciSequence, I get a proper result, but I don't
understand why when looking at the code.
Consider this fragment...
prevTotal := 0.
currTotal := 1.
currTotal := prevTotal + (prevTotal := currTotal).
My understanding was that parentheses are executed first.
(prevTotal := currTotal) - assigns and returns 1
currTotal := prevTotal + (1)
and since prevTotal = 1
currTotal := 1 + (1)
prevTotal = 1.
currTotal = 2.
Yet what appears to be happening is...
prevTotal = 0
currTotal := 0 + (prevTotal := currTotal)
then the parentheses...
currTotal := 0 + (1)
prevTotal = 1.
currTotal = 1.
Care to school me?
Thanks!
Russ
--
Russ Whaley
whaley.russ@gmail.com
Hi,
don't forget to read the expression from left to right:
currTotal := prevTotal + (prevTotal := currTotal).
5 1 4 3 2
Kind regards,
Steffen
Am .09.2020, 15:05 Uhr, schrieb Russ Whaley whaley.russ@gmail.com:
Can someone please explain this? I'm guessing I don't understand order of
execution.
When perusing >>fibonacciSequence, I get a proper result, but I don't
understand why when looking at the code.
Consider this fragment...
prevTotal := 0.
currTotal := 1.
currTotal := prevTotal + (prevTotal := currTotal).
My understanding was that parentheses are executed first.
(prevTotal := currTotal) - assigns and returns 1
currTotal := prevTotal + (1)
and since prevTotal = 1
currTotal := 1 + (1)
prevTotal = 1.
currTotal = 2.
Yet what appears to be happening is...
prevTotal = 0
currTotal := 0 + (prevTotal := currTotal)
then the parentheses...
currTotal := 0 + (1)
prevTotal = 1.
currTotal = 1.
Care to school me?
Thanks!
Russ