Yes, first I build the list of primes, usually up to the square root of the maximum value. If the remaining number is not one after you went through the primes, that "remainder" is prime.Do you have a list of the primes to do this? Until which number? If not, how can you "go through primes in order"?
Now, how do I build the list of primes? I went through several different ways until I found out that (for me) sieve was the best way. Sometimes you can use just the sieve, or (like I did in this case), you do the sieve and then go through the sieve once and put all the primes into a list.
So, how do you do the sieve?
You know how it works? You start with 2 and mark all the multiples of 2. Then you find next unmarked (it will be 3) and mark all its multiples and so on. Note that you can start marking them from the square of the unmarked one (beacuse all smaller multiples were already marked). And you can stop looking for unmarked ones once you get to the square root of the sieve size. I will post the code I use if you want me to, but you might want to try building your own.
I hope this helped.