I play a little with Lua.
I came across the following piece of code that has unexpected behavior:
a = 3; b = 5; c = a-- * b++; // some computation print(a, b, c);
Lua launches the program without any errors, but does not print 2 6 15 as expected. Why?
2 6 15
-- launches one line comment , for example # or // in other languages.
--
#
//
So this is equivalent to:
a = 3; b = 5; c = a
LUA does not increase or decrease with ++ and -- . -- will start a comment instead.
++
If you want 2 6 15 as output, try this code:
a = 3 b = 5 c = a * b a = a - 1 b = b + 1 print(a, b, c)
It will give
3 5 3
because the 3rd row will be evaluated as c = a
why? because in lua comments start with -. Therefore c = a-- * b ++; // calculation
estimated as two parts: