Hi Doug, If you run your code in a workspace with 'do-it' command, it runs in the UI smalltalk process and the only way to cancel it is the cancel key You shoud run your code in a separate process like: x := MyClass2 new [x myLoop ] forkAt: Processor systemBackgroundPriority. forkAt:... forks the block in another smalltalk process. like this you will be able to tell your x object to stop looping from your workspace (by setting a boolean in your object's member), or you could terminate it or debug it with the Process browser. HTH, Cheers Alain "DougEdmunds" <dougedmunds@gmail.com> a écrit dans le message de news: 1303416534118-3466747.post@n4.nabble.com...
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>)
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-tp3466747p... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.