布尔上下文中使用的非布尔值(UInt16)

时间:2018-03-28 03:46:58

标签: julia

我收到一个错误: TypeError:布尔上下文中使用的非布尔值(UInt16)

经过一些调试后,错误来自这个while循环。

current_value = UInt16(6)
bit = UInt16(8)
while (current_value & bit)
    bit >>= 1
end

怎么了?

1 个答案:

答案 0 :(得分:0)

经过一些测试后,似乎Julia中的while循环不会默认测试非零为true。所以我需要明确添加!=0

current_value = UInt16(6)
bit = UInt16(8)
while (current_value & bit != 0)
    bit >>= 1
end