1 2 3 4 5 6 7 | irb(main):001:0> def loop(interrupt) irb(main):002:1> for i in 1..10 irb(main):003:2> puts "Value of i: #{i}" irb(main):004:2> callcc {|c| return c} if i == interrupt irb(main):005:2> end irb(main):006:1> end => nil |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | irb(main):007:0> cont = loop 5 Value of i: 1 Value of i: 2 Value of i: 3 Value of i: 4 Value of i: 5 => #<Continuation:0x2b5a358> irb(main):008:0> cont.call Value of i: 6 Value of i: 7 Value of i: 8 Value of i: 9 Value of i: 10 => 1 10 irb(main):009:0> cont = loop 8 Value of i: 1 Value of i: 2 Value of i: 3 Value of i: 4 Value of i: 5 Value of i: 6 Value of i: 7 Value of i: 8 => #<Continuation:0x2b562f0> irb(main):010:0> cont.call Value of i: 9 Value of i: 10 |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |