On Fri, 17 Sep 2010 at 01:25AM -0700, Michael wrote: > The Algorithm works as follows: > > Initialize the value for p > G←−2 > for i from 1 to p − 1 do > G ← (G^2 + 12)^2/(4 · G · (G^2 − 12)) (mod Mp) > If G does not exist, then stop the Algorithm, Mp is not prime > end do > If G = 0 then Mp is prime > else Mp is not prime > > How can I interrupt the loop? I tried a try...except statement, but it > seems that the ringarithmetic of Sage doesn't produce an error if an > element to be divided by is not invertible.
You can break out of loops in Python/Sage with "break":
for i in range(100):
# do stuff
if i == 50:
break
# do more stuff
In the above loop, when i hits 50, it will "do stuff", and then jump out
of the loop and continue.
Dan
--
--- Dan Drake
----- http://mathsci.kaist.ac.kr/~drake
-------
signature.asc
Description: Digital signature
