我在SWIFT新的基于iOS开发者库,我发现这个条件语句代码:如何正确写入条件语句?
if *condition 1* {
*statements to execute if condition 1 is true*
} else if *condition 2* {
*statements to execute if condition 2 is true*
} else {
*statements to execute if both conditions are false*
}
但我想是这样的:
if *condition 1* {
*statements to execute if condition 1 is true*
} else {
*statements to execute if condition 1 is false*
}
if *condition 2* {
*statements to execute if condition 2 is true*
} else {
*statements to execute if condition 2 is false*
}
if *condition 3* {
*statements to execute if condition 3 is true*
} else {
*statements to execute if condition 3 is false*
}
if *condition 4* {
*statements to execute if condition 4 is true*
} else {
*statements to execute if condition 4 is false*
}
有没有什么解决方案,作出正确的如果我的问题听起来很愚蠢,我很抱歉?
你的第二个代码块应完全按照您写的,问题出在哪里:
最简单的形式,一个switch语句对同一类型的一个 或多个值的值进行比较? –