On Thu, Apr 21, 2011 at 10:08 PM, DougEdmunds <[email protected]> wrote:

> I created a class that generates an endless loop. For this example, the
> loop
> just prints 1-10, back and forth. I'd like to stop the loop by using code,
> but when it is running, I can't type anything in a workspace.  The only way
> I can stop it is by a manual interrupt (on XP, using Alt-<period key>)
>
>

I have no idea how to do it. But all I know is that no matter whether you
use a UI or type something manually, at the end everything is an object +
message send.
So..what I am saying is that you can check what the interruption keys  does
and do it by code or take the idea and do something similar.

Check UserInterruptHandler, its users, etc...

Cheers

Mariano

BTW if you find it, let us know



> Typical run:
> x := MyClass2 new.
> x myLoop.
>
> I want to type "x stopLoop" which would set the running variable to false.
>
> How do I do this?
>
> --------
>
> 'From Pharo1.3a of ''18 January 2011'' [Latest update: #13144] on 21 April
> 2011 at 12:59:14 pm'!
> Object subclass: #MyClass2
>        instanceVariableNames: 'running'
>        classVariableNames: ''
>        poolDictionaries: ''
>        category: 'Sandbox0419'!
>
> !MyClass2 methodsFor: 'as yet unclassified' stamp: 'DougEdmunds 4/21/2011
> 12:54'!
> initialize
>        super initialize.
>        running  := true.
>        Transcript clear.
>      Transcript show: 'try to stop the loop somehow' .
>        ! !
>
> !MyClass2 methodsFor: 'as yet unclassified' stamp: 'DougEdmunds 4/21/2011
> 12:54'!
> myLoop
>
>    "running is an instance variable, initialized to true."
>
>        | x up |
>        Transcript clear.
>        x := 1.
>        up := true.
>        [Transcript show: x; cr.
>                x >= 10 ifTrue: [up :=false].
>                x <= 1 ifTrue: [up := true].
>                up ifTrue: [x := x + 1] ifFalse: [x := x - 1].
>                (Delay forSeconds: 1) wait.
>                running ifFalse: [^ x].
>        ] repeat.
> ! !
>
> !MyClass2 methodsFor: 'as yet unclassified' stamp: 'DougEdmunds 4/21/2011
> 12:55'!
> stopLoop
>        running := false.
>        ! !
> --------
>
> --
> View this message in context:
> http://forum.world.st/How-to-break-out-of-endless-loop-using-code-tp3466747p3466747.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>


-- 
Mariano
http://marianopeck.wordpress.com

Reply via email to