Skip to content

Commit 8466d89

Browse files
committed
---
yaml --- r: 64891 b: refs/heads/snap-stage3 c: a696f0f h: refs/heads/master i: 64889: bba4197 64887: 0c4f003 v: v3
1 parent c378159 commit 8466d89

7 files changed

+152
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 62b6fa094378340574bf40543cdcd477f4dd1169
4+
refs/heads/snap-stage3: a696f0fecb9d11204f64d310eb66e095f64bd04a
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x = [1,..100];
13+
let mut y = 0;
14+
foreach i in x.iter() {
15+
if y > 10 {
16+
break;
17+
}
18+
y += *i;
19+
}
20+
assert!(y == 11);
21+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::hashmap::HashMap;
12+
13+
// This is a fancy one: it uses an external iterator established
14+
// outside the loop, breaks, then _picks back up_ and continues
15+
// iterating with it.
16+
17+
fn main() {
18+
let mut h = HashMap::new();
19+
let kvs = [(1, 10), (2, 20), (3, 30)];
20+
foreach &(k,v) in kvs.iter() {
21+
h.insert(k,v);
22+
}
23+
let mut x = 0;
24+
let mut y = 0;
25+
26+
let mut i = h.iter();
27+
28+
foreach (&k,&v) in i {
29+
x += k;
30+
y += v;
31+
break;
32+
}
33+
34+
foreach (&k,&v) in i {
35+
x += k;
36+
y += v;
37+
}
38+
39+
assert_eq!(x, 6);
40+
assert_eq!(y, 60);
41+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::hashmap::HashMap;
12+
13+
fn main() {
14+
let mut h = HashMap::new();
15+
let kvs = [(1, 10), (2, 20), (3, 30)];
16+
foreach &(k,v) in kvs.iter() {
17+
h.insert(k,v);
18+
}
19+
let mut x = 0;
20+
let mut y = 0;
21+
foreach (&k,&v) in h.iter() {
22+
x += k;
23+
y += v;
24+
}
25+
assert_eq!(x, 6);
26+
assert_eq!(y, 60);
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x = [1,..100];
13+
let mut y = 0;
14+
foreach (n,i) in x.iter().enumerate() {
15+
if n < 10 {
16+
loop;
17+
}
18+
y += *i;
19+
}
20+
assert_eq!(y, 90);
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x = [1,..100];
13+
let y = [2,..100];
14+
let mut p = 0;
15+
let mut q = 0;
16+
foreach i in x.iter() {
17+
foreach j in y.iter() {
18+
p += *j;
19+
}
20+
q += *i + p;
21+
}
22+
assert!(q == 1010100);
23+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let x = [1,..100];
13+
let mut y = 0;
14+
foreach i in x.iter() {
15+
y += *i
16+
}
17+
assert!(y == 100);
18+
}

0 commit comments

Comments
 (0)