Lua中如何将if语句的链接逻辑操作转换为长尾?
- 内容介绍
- 文章标签
- 相关推荐
本文共计242个文字,预计阅读时间需要1分钟。
这是Lua中最高效的方法吗?谢谢!+ if X==0 and Y==0 then if X1==960 and Y1==720 then someCode() else end endelse end+避免使用嵌套的if语句是个好主意,尤其是如果检查我会尝试单个条件。最好的方法是分析功能,看看看是否需要区分不同的情况。
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
本文共计242个文字,预计阅读时间需要1分钟。
这是Lua中最高效的方法吗?谢谢!+ if X==0 and Y==0 then if X1==960 and Y1==720 then someCode() else end endelse end+避免使用嵌套的if语句是个好主意,尤其是如果检查我会尝试单个条件。最好的方法是分析功能,看看看是否需要区分不同的情况。
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

