rust(72)-match匹配
生活随笔
收集整理的這篇文章主要介紹了
rust(72)-match匹配
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
fn main() {for n in 2..101{let num1=n % 2;let num2=n % 7;match num1 {0=>println!("{:?} 偶數(shù)",n),1=>println!("{:?} 奇數(shù)",n),_ =>println!("{:?} other",n),} match num2 {1...3 =>println!("{:?} 1-3",n),5|6 =>println!("{:?} 5-6",n),_ =>println!("{:?} other",n),}}
}
2 偶數(shù)
2 1-3
3 奇數(shù)
3 1-3
4 偶數(shù)
4 other
5 奇數(shù)
5 5-6
6 偶數(shù)
6 5-6
...
99 奇數(shù)
99 1-3
100 偶數(shù)
100 1-3
總結(jié)
以上是生活随笔為你收集整理的rust(72)-match匹配的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: rust(71)-for、while循环
- 下一篇: python精要(72)-函数参数列表副