fnnext_fiber(a: &muti32, b: &muti32) { let c = *a + *b; *a = *b; *b = c; }
fnfib_loop(n: u8) { letmut a = 1; letmut b = 1; letmut i = 2u8; loop { // let c = a + b; // a = b; // b = c; next_fiber(&mut a, &mut b); i += 1; println!("next val is {}", b); if i >= n { break; } } } fnfib_while(n: u8) { let (mut a, mut b, mut i) = (1, 1, 2); while i < n { // let c = a + b; // a = b; // b = c; next_fiber(&mut a, &mut b); i += 1; println!("next val is {}", b); } } fnfib_for(n: u8) { let (mut a, mut b) = (1, 1); for _i in2..n { // let c = a + b; // a = b; // b = c; next_fiber(&mut a, &mut b); println!("next val is {}", b); } } fnmain() { let n = 10; fib_loop(n); fib_while(n); fib_for(n); }