Lua - Conditional Assignment

Published 2014/03/03 by Admin in LUA
Tags: , , , , ,

We are able to take a bit of the long-windedness of the "if, else" statement away by using conditional assignment.

a=1

b=(a==1) and "one" or "not one"

The code above is the same as the code below.

a=1

if a==1 then

b = "one"

else 

b = "not one"

end

As you can see conditional assignment removes a lot of unnecessary code.


Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

my coding

This is a collection of all the coding gems I have found and would like to share with the world!