![]() |
![]() |
#1 |
"Ed Hall"
Dec 2009
Adirondack Mtns
22·5·263 Posts |
![]()
pari gurus,
Can you tell me why I can't seem to get the break command to break within a loop, instead of executing the rest of the loop prior to breaking? Code:
findcycle(a,b)= { for(e=a,b, i=e; for(c=1,10, i=sigma(i)-i; if(i<e, break()); if(i==e, print(i," ",c); break())); print(e)) } BTW, I have tried next(), with identical results. I guess along an alternate route, is there an else type command? Thanks! |
![]() |
![]() |
![]() |
#2 |
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2
235138 Posts |
![]()
No, they do. The inner loop is indeed broken when you ordered it _and then_ print(e) is executed. Because it is outside of the inner loop.
|
![]() |
![]() |
![]() |
#3 |
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2
235138 Posts |
![]()
If you indent your own code correctly, you will see it easier:
Code:
findcycle(a,b)= { for(e=a,b, i=e; for(c=1,10, i=sigma(i)-i; if(i<e, break()); if(i==e, print(i," ",c); break()) ); print(e) ) } |
![]() |
![]() |
![]() |
#4 |
"Ed Hall"
Dec 2009
Adirondack Mtns
122148 Posts |
![]()
Thanks! I was chopping down a much more involved version and didn't do a good job. That will teach me - probably not.
(I'm glad I used my actual code, instead of "constructing" something for the post...) Again, thanks! |
![]() |
![]() |
![]() |
#5 |
"Serge"
Mar 2008
Phi(4,2^7658614+1)/2
3·7·479 Posts |
![]()
Oh, I do it myself all the time. When I prototype PE problems in Pari, I frequently type a monstrous ever-growing one-liner (without indentation, obviously). It's a pain to watch later. Here's an example:
Code:
forprime(p=2,10000,if(p%10==1||p%10==9,d=divisors(p-1);for(j=2,#d,i=d[j]*p;if(i>10^8,break);if(fibonacci(i)%p^2==0,write("presieve1",p" "i);break)))) |
![]() |
![]() |
![]() |
#6 | |
"Ed Hall"
Dec 2009
Adirondack Mtns
148C16 Posts |
![]() Quote:
Hmm... I'm rambling... Gotta go. Thanks again. |
|
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
LLL in GP/Pari | paul0 | Programming | 2 | 2015-11-17 13:04 |
Break up songs | davieddy | Lounge | 4 | 2013-03-17 01:26 |
Did that guy actually break the the sound barrier? | davieddy | Puzzles | 47 | 2012-10-19 21:12 |
What do I have to do to break free? | fivemack | Aliquot Sequences | 8 | 2010-04-08 18:47 |
64-bit Pari? | CRGreathouse | Software | 2 | 2009-03-13 04:22 |