On Wed, Oct 24, 2012 at 8:19 PM, Henri Sivonen <[email protected]> wrote:
> Looping over a part of an array by index and moving on immediately
> when a “not interested” condition matches.
>
> Stuff like
> for (int i = start; i < end; i++) {
> char c = buf[i];
> ...
> if (c == uninteresting) {
> continue;
> }
> ...
> }
You might be able to bend macros into something you want. For example:
macro_rules! my_loop(
($cond:expr, $inc:expr, $body:expr) => {
while $cond {
while $cond {
$body;
$inc;
}
$inc;
}
};
)
fn main () {
io::println("hello");
let mut i = 0;
my_loop!(i < 10, i += 1, {
if i < 5 { break; }
io::println("foo");
})
}
Here 'break' inside the macro is your 'continue' and in the example "i
< 5" is the uninteresting check. I don't know how, in rust, to change
all uses of some_string into "($inc; loop)" but if you can you can do
better than this example.
Chris.
--
http://www.bluishcoder.co.nz
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev