aboutsummaryrefslogtreecommitdiff
path: root/src/test/run-pass/foreach-nested.rs
diff options
context:
space:
mode:
authorJason Orendorff <[email protected]>2010-07-16 12:24:28 +0800
committerGraydon Hoare <[email protected]>2010-07-16 14:53:49 +0800
commit7671828d45ea3b0d2f3814fc59bb01cba3d481d5 (patch)
treefa4f7c58465350e4aea9e35f8b0f7db8c751a597 /src/test/run-pass/foreach-nested.rs
parentUpdate AUTHORS.txt. (diff)
downloadrust-7671828d45ea3b0d2f3814fc59bb01cba3d481d5.tar.xz
rust-7671828d45ea3b0d2f3814fc59bb01cba3d481d5.zip
Support nested for-each loops. Closes #79.
Diffstat (limited to 'src/test/run-pass/foreach-nested.rs')
-rw-r--r--src/test/run-pass/foreach-nested.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/run-pass/foreach-nested.rs b/src/test/run-pass/foreach-nested.rs
new file mode 100644
index 00000000..848adb26
--- /dev/null
+++ b/src/test/run-pass/foreach-nested.rs
@@ -0,0 +1,23 @@
+// -*- rust -*-
+
+iter two() -> int {
+ put 0;
+ put 1;
+}
+
+fn main() {
+ let vec[int] a = vec(-1, -1, -1, -1);
+ let int p = 0;
+
+ for each (int i in two()) {
+ for each (int j in two()) {
+ a.(p) = 10 * i + j;
+ p += 1;
+ }
+ }
+
+ check (a.(0) == 0);
+ check (a.(1) == 1);
+ check (a.(2) == 10);
+ check (a.(3) == 11);
+}