blob: bd3799e47e1e52c78461a118a7e8c09660b18d32 [file] [log] [blame]
Graydon Hoared1affff2012-12-11 01:32:481// 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
Graydon Hoarece729932011-06-15 18:19:5011
12
Patrick Waltond18f7852013-03-07 22:38:3813fn pairs(it: &fn((int, int))) {
Niko Matsakisdc072802012-03-22 15:39:4114 let mut i: int = 0;
15 let mut j: int = 0;
Marijn Haverbeke050170d2011-10-21 11:14:2816 while i < 10 { it((i, j)); i += 1; j += i; }
Graydon Hoared6b7c962010-06-24 04:03:0917}
18
Graydon Hoare89c8ef72013-02-02 03:43:1719pub fn main() {
Niko Matsakisdc072802012-03-22 15:39:4120 let mut i: int = 10;
21 let mut j: int = 0;
Brian Andersond1fc2b52012-06-30 23:19:0722 do pairs() |p| {
Marijn Haverbeke050170d2011-10-21 11:14:2823 let (_0, _1) = p;
Huon Wilsone4f75612013-07-16 17:08:0824 info!(_0);
25 info!(_1);
Corey Richardsoncc57ca02013-05-19 02:02:4526 assert_eq!(_0 + 10, i);
Graydon Hoarece729932011-06-15 18:19:5027 i += 1;
Marijn Haverbeke050170d2011-10-21 11:14:2828 j = _1;
29 };
Corey Richardsoncc57ca02013-05-19 02:02:4530 assert_eq!(j, 45);
Lindsey Kuperf91351a2011-08-16 04:54:5231}