Le 01/02/2013 13:45, Alexander Stavonin a écrit :
I guess, the solution will not work for -1 … -10

Oh, for negative steps my previous implementation is buggy indeed.
But it can be fixed:

pub pure fn range_step(lo: int, hi: int, step: int,
                      it: fn(int) -> bool) {
   let mut i = lo;
   if step > 0 {
       while i < hi {
           if !it(i) { break }
           i += step;
       }
   } else if step < 0 {
       while i > hi {
           if !it(i) { break }
           i += step;
       }
   } else {
       fail "Got step = 0."
   }
}


for range_step(-1, -11, -1) |i| { … }

--
Simon Sapin
_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to