I made a piece of code to check if a number was prime, which originally used manual inputs, but I changed it because I didn’t want to give myself carpal tunnel. How do I get it to skip to the next value instead of stopping the script?
Hi, welcome to Snap!!
One thing you can do is use the FOR block:
Well, first of all, you should learn to love procedures (custom blocks). So if your goal is
to check if a number was prime
then you should make a predicate block that takes one number as input:
Then you can use that block in a calling script that looks at several numbers:
… or whatever you want to do with a prime number instead of SAY it, e.g., ADD it to a list.
There are lots of ways you could speed this up, e.g., just check for divisors up to \sqrt{number}, or even just check the divisors you already know are prime.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.


