I want to know how I find, calculate (make a list in Mathematica) for thefirts 50 twin primes. If p is a prime and p+2 is a prime they called twin primes. Anybody who can tell me to programing the program WolframMathematica?

I have come this far, so long:

1) I make a new empty list, that I'm calling "twins"

twins = {}

{}

2) I know that the first twins is 3, 5 and put the element to the list:

AppendTo[twins, {3, 5}]

{{3, 5}}

twins

{{3, 5}}

Ok!

3) I'm checking if the next prime 3+2=5 have a twin and use my conditions:

n = 5

5

If[PrimeQ[n] && PrimeQ[n + 2], AppendTo[twins, {n, n + 2}]]

{{3, 5}, {5, 7}}

Ok!

4) Then I'm checking the lengt of my list:

Length[twins]

2

I's ok!

4)It's ok, but the last thing I want to tell Mathematica is to use the comand "While" and do this:

As long as "twins" has less than 50 elements:

Testifboth nandn+2 are primes.

Ifit is so: put {n,n+2} to the list "twins",thenincrese

n whith 2 and thenreturnthe list "twins".

If you can help you can also send me a Mathematica-file whith the solution (nb-file). toanders.skoog@vaxjofria.seoranders.k.m.skoog@home.se, or just write it down here at the forum. Thanks.