【发布时间】:2022-08-12 19:36:24
【问题描述】:
假设我们有程序is_even如果给定的数字是偶数,则返回!
这是一个很好的代码:
if is_even(22) = true or test(1) = true or test(2) = true then
//...
甚至那更好:
if true in [ is_even(22), is_even(1), is_even(2) ] then
//..
但是如果我这样做但有逻辑怎么办(and不是or) 像那样
if is_even(22) = true and test(1) = true and test(2) = true then
//...
更好的代码会是什么?
我尝试过这样做,所以我想用python all 中的函数来做到这一点:
local procedure all(array_bools : ARRAY [3] OF Boolean): Boolean
var
bool: Boolean;
i: Integer;
begin
REPEAT
bool := array_bools[i];
if bool = false then
exit(false);
i := i + 1;
UNTIL i <> ARRAYLEN(array_bools);
exit(false);
end;
它没有像我预期的那样工作
if all([is_even(22), is_even(1), is_even(2)]) = true then
-
这似乎过于复杂。为什么不只是
if not array_bools[i] then exit(false);?同样<> ARRAYLEN(array_bools)从一开始就注定了。你想要> ARRAYLEN(array_bools),因为当i = 0(数组的开始)它自动<> ARRAYLEN(array_bools)
标签: microsoft-dynamics dynamics-al businesscentral msdyn365bc