# Continuation

**URL:** <https://www.ruby-forum.com/t/continuation/101179>\
**Category:** Ruby\
**Created:** [February 5, 2006, 2:15am UTC](https://www.ruby-forum.com/t/continuation/101179 "2006-02-05T02:15:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SchSSS\_le\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a183cd/32.png) [@SchSSS\_le\_Daniel](https://www.ruby-forum.com/u/SchSSS_le_Daniel)\
**Post date:** [February 5, 2006, 2:15am UTC](https://www.ruby-forum.com/t/continuation/101179/1 "2006-02-05T02:15:14Z")

</div>

Hello,

irb(main):005:0\* cnt=0  
=\> 0  
irb(main):006:0\> cc=nil  
=\> nil  
irb(main):007:0\> callcc {|cc|}  
=\> nil  
irb(main):008:0\> cnt+=1  
=\> 1  
irb(main):009:0\> cc.call if cnt \< 10  
=\> nil  
irb(main):010:0\> cnt  
=\> 1  
irb(main):011:0\>  
irb(main):012:0\* RUBY\_VERSION  
=\> “1.8.4”  
irb(main):013:0\>

this example is from

> **[WebMD - Better information. Better health.](https://www.webmd.com/?Continuations)**
>
> The leading source for trustworthy and timely health and medical news and information. Providing credible health information, supportive community, and educational services by blending award-winning expertise in content, community services, expert...

and cnt should become 10

I also tried some other examples from the net  
and it worked only in this case

irb(main):014:0\* callcc do |cc|  
irb(main):015:1\* for i in 0…10  
irb(main):016:2\> print "\n#{i}: "  
irb(main):017:2\> for j in 0…10  
irb(main):018:3\> cc.call if j == 5 and i == 5  
irb(main):019:3\> printf “%3i”, j  
irb(main):020:3\> end  
irb(main):021:2\> end  
irb(main):022:1\> end

0: 0 1 2 3 4 5 6 7 8 9 10  
1: 0 1 2 3 4 5 6 7 8 9 10  
2: 0 1 2 3 4 5 6 7 8 9 10  
3: 0 1 2 3 4 5 6 7 8 9 10  
4: 0 1 2 3 4 5 6 7 8 9 10  
5: 0 1 2 3 4=\> nil  
irb(main):023:0\>

Maybe someone can help

Regards, Daniel

---

<div class="post-metadata">

**Author:** ![SchSSS\_le\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a183cd/32.png) [@SchSSS\_le\_Daniel](https://www.ruby-forum.com/u/SchSSS_le_Daniel)\
**Post date:** [February 5, 2006, 2:30am UTC](https://www.ruby-forum.com/t/continuation/101179/2 "2006-02-05T02:30:26Z")

</div>

On Sun, 05 Feb 2006 02:49:58 -0000, SchÃ¼le Daniel  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> irb(main):010:0\> cnt  
> =\> 1  
> irb(main):011:0\>  
> irb(main):012:0\* RUBY\_VERSION  
> =\> “1.8.4”  
> irb(main):013:0\>
> 
> this example is from  
> [http://www.rubygarden.org/ruby?Continuations](http://www.rubygarden.org/ruby?Continuations)  
> and cnt should become 10

I’ve found that certain things like continuations don’t work well under  
IRB. I think it’s because of the way it’s workspaces work.

That code works fine as a script.

---

<div class="post-metadata">

**Author:** ![SchSSS\_le\_Daniel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a183cd/32.png) [@SchSSS\_le\_Daniel](https://www.ruby-forum.com/u/SchSSS_le_Daniel)\
**Post date:** [February 5, 2006, 2:36am UTC](https://www.ruby-forum.com/t/continuation/101179/3 "2006-02-05T02:36:29Z")

</div>

[Schüle Daniel [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), 2006-02-05 01.58 CET]

> irb(main):009:0\> cc.call if cnt \< 10  
> and cnt should become 10  
> The problem is IRB. It is a ruby program whose main loop reads your  
> input,  
> evaluates it, and shows you the result, so when you call the  
> continuation,  
> it only returns to the point where it shows you the result of your  
> input;  
> it doesn’t evaluate the statementes you entered later.

Try the example outside IRB.
