游乐场执行失败:<expr>:15:33:错误:输入&#39; Int&#39;不符合协议&#39; BooleanType&#39; </expr>

时间:2014-09-21 02:13:07

标签: ios if-statement for-loop swift logical-operators

我正在使用Swift创建一个简单的Fizz Buzz Generator

我收到以下错误:

Playground execution failed: <EXPR>:15:33: error: type 'Int' does not conform to protocol 'BooleanType'
    } else if (number % 3 == 0) && (number % 5) {

这就是我所拥有的:

for number in 1...100 {
    if (number % 3 == 0) {
        println("Fizz")
    } else if (number % 5 == 0) {
        println("Buzz")
    } else if (number % 3 == 0) && (number % 5) {
        println("Fizz Buzz")
    } else {
        println(number)
    }
}

1 个答案:

答案 0 :(得分:3)

你错过了一些逻辑。变化

else if (number % 3 == 0) && (number % 5)

else if (number % 3 == 0) && (number % 5 == 0)