mersenneforum.org pari break() usage
 Register FAQ Search Today's Posts Mark Forums Read

 2012-10-25, 02:10 #1 EdH     "Ed Hall" Dec 2009 Adirondack Mtns 4,507 Posts pari break() usage 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
2012-10-25, 02:18   #2
Batalov

"Serge"
Mar 2008
Phi(4,2^7658614+1)/2

11×19×47 Posts

Quote:
 Originally Posted by EdH I want the ifs to break out of the inner loop immediately, but they don't; they continue to the end of the loop invoking the print(e).
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.

 2012-10-25, 02:21 #3 Batalov     "Serge" Mar 2008 Phi(4,2^7658614+1)/2 100110010111112 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
2012-10-25, 02:52   #4
EdH

"Ed Hall"
Dec 2009

4,507 Posts

Quote:
 Originally Posted by Batalov If you indent your own code correctly, you will see it easier:
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!

 2012-10-25, 03:04 #5 Batalov     "Serge" Mar 2008 Phi(4,2^7658614+1)/2 11·19·47 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)))) (I rewrote it in C, later; Not only rewrote much prettier but without even touching fibonacci(); this was just brainstorming -- Uggggh!)
2012-10-25, 03:40   #6
EdH

"Ed Hall"
Dec 2009

450710 Posts

Quote:
 Originally Posted by Batalov 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)))) (I rewrote it in C, later; Not only rewrote much prettier but without even touching fibonacci(); this was just brainstorming -- Uggggh!)
I used to write stuff like that in a single cell in Excel - I kept bumping up against the character limit. I still have a scoring workbook in use in several places across the country that won't work with greater than 999 competitors due to the cell limitation (unless newer versions expanded that limit). I've been trying to clean my code up lately, what code I still write. Someday, I have to actually comment things. I've run into the problem of not being able to read my own code for lack of comments.

Hmm... I'm rambling... Gotta go.

Thanks again.

 Similar Threads Thread Thread Starter Forum Replies Last Post paul0 Programming 2 2015-11-17 13:04 davieddy Lounge 4 2013-03-17 01:26 davieddy Puzzles 47 2012-10-19 21:12 fivemack Aliquot Sequences 8 2010-04-08 18:47 CRGreathouse Software 2 2009-03-13 04:22

All times are UTC. The time now is 07:18.

Sun May 22 07:18:57 UTC 2022 up 38 days, 5:20, 0 users, load averages: 0.74, 0.89, 1.01