初級 › if の条件式に整数を渡すと E0308(expected bool)になる › パターン1
if の条件式に整数を渡すと E0308(expected bool)になる
C言語やJavaScriptと違い、Rustのif文の条件式には真偽値(bool)しか書けません。
1 fn main() { 2 let flag = ______; ^ 3 if flag { 4 println!("yes"); 5 } 6 }
error[E0308]: mismatched types
expected `bool`, found integer
空欄を埋めて実行を通す
Rustのif条件式にはbool型しか書けません。整数の0/1を真偽値として扱う暗黙変換はありません。
次の問題