Recent Changes - Search:



edit SideBar


An endless loop is easy to create.

[block of code] repeat.

The key question is how do I get out of the endless loop?

The usual method is to have a return (^) inside the loop that is triggered by some event, that can be evaluated by an ifTrue: or ifFalse: test. For example, a boolean (myBoolean) is set to false before entering the loop. Some code inside the loop is expected to change myBoolean to true (such as '(localTemperature > 100) ifTrue: myBoolean := true. ^nil'

If no code inside the loop will terminate the loop, then you have an endless loop. In order to terminate that loop you still need a condition ('myBoolean ifTrue: ^nil'), but you create the change to myBoolean outside the loop.

The problem you immediately encounter is that unless the loop is running at a process priority lower than the rest of the code (and the desktop), you won't be able to interrupt it. For example, if an endless loop gets started, you won't be able to type into a Workspace or access the World menu.

A place where you see this kind of 'lockup' is when you install a package through Monticello, or scan source through Finder. Until that code finishes what it is doing, your user input (button clicks, etc), gets buffered to run next, but won't interrupt the code. If the code is an endless loop, you can change priorities of the processes.

Edit - History - Print - Recent Changes - Search
Page last modified on May 01, 2011, at 11:38 AM