It's also possible to write something like python's enumerate, to get: for enumerate(some_vector) Ii, e| { ... }
In general, rust loops are closer to Python's and functional map than C++'s looping constructs. On 1 February 2013 12:37, Simon Sapin <simon.sa...@exyr.org> wrote: > Le 01/02/2013 13:28, Alexander Stavonin a écrit : > >> Thanks, it better than nothing, but… It works only for i++; how can I >> write /i += 2 /or /i--/? >> > > The range() function is very simple: > > https://github.com/mozilla/**rust/blob/release-0.5/src/** > libcore/int-template.rs#L48<https://github.com/mozilla/rust/blob/release-0.5/src/libcore/int-template.rs#L48> > > #[inline(always)] > /// Iterate over the range [`lo`..`hi`) > pub fn range(lo: T, hi: T, it: fn(T) -> bool) { > let mut i = lo; > while i < hi { > if !it(i) { break } > i += 1 as T; > } > } > > > It’s quite easy to write your own variant with a "step" parameter: > > pub pure fn range_step(lo: int, hi: int, step: int, > it: fn(int) -> bool) { > let mut i = lo; > while i < hi { > if !it(i) { break } > i += step; > } > } > > > Maybe range_step() could be added to libcore? > > -- > Simon Sapin > > ______________________________**_________________ > Rust-dev mailing list > Rust-dev@mozilla.org > https://mail.mozilla.org/**listinfo/rust-dev<https://mail.mozilla.org/listinfo/rust-dev> >
_______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev