12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970fn main() { let y = 1; //if if y == 1 { println!("y = 1 "); } //if - else if y == 1 { println!("y == {}",y); } else { println!("y != 1"); } // if -else if - else if y == 1 {println! ("y = 1");} else if y == 2 { println!("y = 2"); } else if y == 3 { println!("y = 3 "); } else { println!("other!") } //let 中使用if //两个分支中的值应当属于同一类型 let condition = true ; let x = if condition { 5 } else { 6 }; println!("x = {} ",x); //loop let mut counter = 0; loop { println!("in loop"); if counter == 10 { break; } counter += 1; } //let 和 loop let result = loop { counter += 1; if counter == 20 { break counter*2; } }; //while 循环 let mut i = 0; while i != 10 { i+= 1; } println!("i = {}",i); //for 循环 let arr : [u32;5] = [1,2,3,4,5]; //这种方法也可以 //for element in &arr for element in arr.iter() { println!("element = {}",*element); //也可以使用 //println!("element = {}",element); }}