explicit return from a block

A. Kuhn akuhn at gmx.ch
Tue Jun 27 08:31:06 UTC 2006


Implement

BlockClosure>>valueWithExit
    ^self value: [^nil]

And then you can break

 [ :break |
  1 to: 10 do: [ :each |
   each = 7 ifTrue: [ break value ]
  ]
 ] valueWithExit

and continue

  1 to: 10 do: [ :each |
   [ :continue |
    each = 7 ifTrue: [ continue value ]
   ] valueWithExit
  ]

but actually, I never had any reason to use this except when porting
algorithms from Fortran or C...


----- Original Message -----
From: "Viktor Svub" <gilrandir at centrum.cz>
To: <squeak-dev at lists.squeakfoundation.org>
Sent: Tuesday, June 27, 2006 9:23 AM
Subject: explicit return from a block


> Is there any way to explicitly return from a BlockContext/BlockClosure
> (like ^some-expression in methods) but without returning from the parent
> context (method)? I'm beginning to figure out how to avoid the need for
> "break&continue" in loops, and i know that i can even avoid the need for
> explicit return converting the block in question in a method, but there
> are places where a long block is much more convenient...
> thanks
> vsv
>
>




More information about the Squeak-dev mailing list