加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-14 21:43:50 所属栏目:大数据 来源:网络整理
导读:这是在Lua中最有效的方法吗?谢谢! if X = 0 and Y = 0 then if X1 = 960 and Y1 = 720 then someCode() else endelse end 解决方法 避免使用嵌套的if语句是个好主意,如果检查我会尝试单个. 最好的方法是分析功能,看看哪些功能更快. -- Be paranoid and use
这是在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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读