So my question title says it all. What is the best way to calculate $\pi$ as an iterating algorithm that can be programmed into any application (thus the pseudo code)?
$\pi$ Was first calculated using polygons and how an internal perimeter (using a polygon) of a circle compared to the external perimeter (using a polygon) am I correct in saying this? So there must be a way to write the calculation as an iterating algorithm (in pseudo code).
In one of the answers, I found the following formula:

However, I do not understand what it means as I am a novice in mathematics (only middle school!). What I can make out is $\pi$ = $12 * \sum ((-1)^k*(6k)!(13591409 + 545140134k) )/((3k)!*(k!)^3*640420^{3k+3/2})$ The sum function is repeated to however many iterations needed. I don't understand the variable $k$ or where the formula got the numbers e.g. (6k etc).

I feel like your main problem is the summation, does this help?
Why does this work? You won't like the answer; it's highly theoretical and requires far more than middle-school mathematics (I hardly understand it). If you're insistent, check out $\pi$ Formulas and read from formula 80. ("The general form of the series is ...")
May I recommend a simpler formula for computing $\pi$? Perhaps you could check out the Leibniz Series (it takes a while to get enough digits of $\pi$).
Of course, you can calculate $\pi$ by using a computer to inscribe polygons into a perfect circle. This is (1) annoying and (2) really slow compared to algorithms described here.
Another way you could compute $\pi$ which would be really nice for your level would be to use the fact that $x^2 + y^2 = 1$, and so $\sqrt{1-x^2} = y$ gives half a semi-circle, with area of $\pi/2$. By using tiny rectangles to approximate the area, you can calculate $\pi/2$. This is called a Riemann integral.