if语句 – Lua中的链接逻辑操作

这是在Lua中最有效的方法吗?谢谢!

if X >= 0 and Y >= 0 then
    if X1 <= 960 and Y1 <= 720 then
        someCode()
    else end
else end

解决方法

避免使用嵌套的if语句是个好主意,如果检查我会尝试单个.
最好的方法是分析功能,看看哪些功能更快.

-- Be paranoid and use lots of parenthesis:
if ( ( (X >= 0) and (Y >= 0) ) and ( (X1 <= 960) and (Y1 <= 720) ) ) then
    someCode()
end

这是相同的,但更容易阅读.好的代码不仅速度快,而且易于阅读.

local condition1 = ((X >= 0) and (Y >= 0))
local condition2 = ((X1 <= 960) and (Y1 <= 720))

if (condition1 and condition2) then
    someCode()
end

相关文章

1.github代码实践源代码是lua脚本语言,下载th之后运行thmai...
此文为搬运帖,原帖地址https://www.cnblogs.com/zwywilliam/...
Rime输入法通过定义lua文件,可以实现获取当前时间日期的功能...
localfunctiongenerate_action(params)localscale_action=cc...
2022年1月11日13:57:45 官方:https://opm.openresty.org/官...
在Lua中的table(表),就像c#中的HashMap(哈希表),key和...