infinite loops 
Author Message
 infinite loops

Hello,

Is there a more elegant way in Smalltalk to break an infinite loop
(for example a whileTrue condition that sometimes never realize) than
using a counter and a return when this counter is too high?
Thanks for any help

        G.
(hope you will excuse me if this is the second time this message
comes but I have problems with my newsreader)

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Article poste via Voila News - http://www.*-*-*.com/



Wed, 18 Jun 1902 08:00:00 GMT  
 infinite loops

Quote:

>Is there a more elegant way in Smalltalk to break an infinite loop
>(for example a whileTrue condition that sometimes never realize) than
>using a counter and a return when this counter is too high?

I guess you have the following code structure in mind?

[ true <i.e. no break condition> ]
    whileTrue: [ <code>
                         <break condition>
                                ifTrue: [ ^<return value or nil>].
                         <more code>
                        ].

If that is the case, here is a "better" way of doing it, without resorting
to anything esoteric.

[ <code>
  <break condition> ]
    whileTrue: [ <more code>].

I am sure you will agree that the second form is much more readable.

Didier



Wed, 18 Jun 1902 08:00:00 GMT  
 infinite loops

<snip>

Quote:

> [ true <i.e. no break condition> ]
>     whileTrue: [ <code>
>                          <break condition>
>                                 ifTrue: [ ^<return value or nil>].
>                          <more code>
>                         ].

> If that is the case, here is a "better" way of doing it, without resorting
> to anything esoteric.

> [ <code>
>   <break condition> ]
>     whileTrue: [ <more code>].

> I am sure you will agree that the second form is much more readable.

although wrong... you meant whileFalse:...

Rob



Wed, 18 Jun 1902 08:00:00 GMT  
 infinite loops
Thanks for the correction...
Didier


Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Infinite loops

2. Headless VW3.0 hangs/infinite-loops while creating or copying a large ByteString

3. Infinite loop Process Problem

4. Infinite Loop

5. Infinite Loop

6. Best way to prevent infinite loops...

7. Best way to prevent infinite loops...

8. Infinite loop

9. Infinite loop detected in Ada exception manager

10. Infinite loop

11. Infinite looping x86 code.

12. detecting infinite loops

 

 
Powered by phpBB® Forum Software