The int/uint::range methods would seem to do the job: for
uint::range(0, 10) |i| { io::println(fmt!(%u, i)); }
Cheers,
Josh
On 1 February 2013 12:14, Alexander Stavonin a.stavo...@gmail.com wrote:
Have we a pretty looks solution for auto incrementation counters during
loops? I mean something
Actually my first suggestion won't work except in trivial
circumstances (ie. starting from zero). Sorry.
On 1 February 2013 12:32, Josh Matthews j...@joshmatthews.net wrote:
Well, constant increments of N can be simulated with |let i = i * N;|
in the body of the loop. There's an issue open
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
#[inline(always)]
/// Iterate
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
I guess, the solution will not work for -1 … -10
On Feb 1, 2013, at 9:37 PM, 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
Le 01/02/2013 13:38, Lucian Branescu a écrit :
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.
Python’s enumerate() works on any
There's already a function to do this:
fn main() {
for int::range_step(0, 10, 2) |i| {
log(error, i);
}
for int::range_step(10, 0, -1) |i| {
log(error, i);
}
}
On Fri, Feb 1, 2013 at 7:28 AM, Alexander Stavonin
Though note that this function is relatively new, you'll need to be on a
recent unstable version rather than 0.5.
On Fri, Feb 1, 2013 at 8:48 AM, Benjamin Striegel ben.strie...@gmail.comwrote:
There's already a function to do this:
fn main() {
for int::range_step(0, 10, 2) |i| {
Le 01/02/2013 14:50, Benjamin Striegel a écrit :
Though note that this function is relatively new, you'll need to be on a
recent unstable version rather than 0.5.
Is it a bug that it’s not documented?
http://static.rust-lang.org/doc/core/int.html
--
Simon Sapin