fnother_fun2(a:i32, b:i32)->i32{
let result = a + b;return result;}fnother_fun3(a:i32, b:i32)->i32{
//let result = a + b;//result
a + b
}fnmain(){
let a:i32=-1;let b:u32=2;let c:i32=9;let r:i32=other_fun2(a, c);println!("r = {}", r);let r2:i32=other_fun3(a, c);println!("r2 = {}", r2);//语句是执行一些操作,但是不返回值的指令//let y = 1; //语句,不返回值//let x = (let y = 1);//表达式会计算一些值let y ={
let x =1;//x + 1;
x +1};println!("y = {}", y);println!("Hello, world!");}
4. 循环体
fnmain(){
//if let y =0;if y ==1{
println!("y = 1");}//if-elseif y ==1{
println!("y = 1");}else{
println!("y != 1");}//if - else if - elseprintln!("++++++++++++");let y =2;if y ==1{
println!("y = 1");}elseif y ==0{
println!("y = 0");}elseif y ==2{
println!("y = 2");}else{
println!("other");}//let中使用iflet condition =true;let x =if condition {
5}else{
6//"six" //error};println!("x = {}", x);//loopletmut counter =0;loop{
println!("in loop");if counter ==10{
break;}//counter = counter + 1;
counter +=1;}let result =loop{
counter +=1;if counter ==20{
break counter*2;}};println!("result = {}", result);//whileletmut i =0;while i !=10{
i +=1;}println!("i = {}", i);//forprintln!("+++++++++++++++");let arr:[u32;5]=[1,2,3,4,5];//for element in arr.iter() {
for element in&arr {
println!("element = {}", element);}println!("Hello, world!");}
文章评论