rust/src/test/run-pass/block-iter-1.rs

23 lines
416 B
Rust
Raw Normal View History

2011-07-25 18:57:27 -05:00
// xfail-stage0
fn iter_vec[T](&vec[T] v, &block (&T) f) {
for (T x in v) {
f(x);
}
}
fn main() {
auto v = [1,2,3,4,5,6,7];
auto odds = 0;
iter_vec(v,
block (&int i) {
log_err i;
if (i % 2 == 1) {
odds += 1;
}
log_err odds;
});
log_err odds;
assert(odds == 4);
}