我在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語句對同一類型的一個 或多個值的值進行比較? –