Infinite loop while generating a sequence of integers 
Author Message
 Infinite loop while generating a sequence of integers

Hi,

I've got a function that generates the sequence of integers from A to B.

For example: genint(2,5,Q). results in Q = [2, 3, 4, 5].

But if I enter ";", it should result in "no". But instead, it makes an
infinite loop. How can I avoid this loop?



Sat, 08 May 2004 23:04:15 GMT  
 Infinite loop while generating a sequence of integers

Quote:

> Hi,

> I've got a function that generates the sequence of integers from A to B.

> For example: genint(2,5,Q). results in Q = [2, 3, 4, 5].

> But if I enter ";", it should result in "no". But instead, it makes an
> infinite loop. How can I avoid this loop?

try :

genint(X,Y,L):-Y < X,!, genint(Y,X,L).
genint(X,X,[X]):-!.
genint(X,Y,[X|L]):- V is X +1 , genint(V,Y,L).

Jean Michel LECONTE



Sun, 09 May 2004 01:55:31 GMT  
 Infinite loop while generating a sequence of integers

Quote:

> Hi,

> I've got a function that generates the sequence of integers from A to B.

> For example: genint(2,5,Q). results in Q = [2, 3, 4, 5].

> But if I enter ";", it should result in "no". But instead, it makes an
> infinite loop. How can I avoid this loop?

If it hurts when you bang your head against the wall, stop banging your head against the wall.

Now, would you be so kind as to send in your program so that we can see what "this loop" is ?

Bart Demoen



Sun, 09 May 2004 00:57:51 GMT  
 Infinite loop while generating a sequence of integers
thanks! The cut-symbol ('!') was the solution....



Quote:

> > Hi,

> > I've got a function that generates the sequence of integers from A to B.

> > For example: genint(2,5,Q). results in Q = [2, 3, 4, 5].

> > But if I enter ";", it should result in "no". But instead, it makes an
> > infinite loop. How can I avoid this loop?

> try :

> genint(X,Y,L):-Y < X,!, genint(Y,X,L).
> genint(X,X,[X]):-!.
> genint(X,Y,[X|L]):- V is X +1 , genint(V,Y,L).

> Jean Michel LECONTE



Sun, 09 May 2004 05:25:08 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Infinite types sequence

2. SYS3: Builder.MarkErrors ^ generates infinite error markers [0]

3. Infinite precision integer routines in Forth?

4. Infinite loops

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

6. infinite loops

7. Infinite loop Process Problem

8. Infinite Loop

9. Infinite Loop

10. Best way to prevent infinite loops...

11. Best way to prevent infinite loops...

12. Infinite loop

 

 
Powered by phpBB® Forum Software