It's worth noting that the other answers here do not calculate the same thing as calculating $r$ at the end. They use the current value of $\bar{x}$ for each step of accumulation, rather than the true value for all steps. They are an approximation, and are likely to be similar, but not exactly the same.
On Wikipedia, there is a re-arrangement of the formula that allows "a convenient single-pass algorithm" which allows you to calculate the correct value at any time-step.
$$ r_{xy} = \frac{\left(\sum_i x_iy_i\right) - n\bar{x}\bar{y}}
{\sqrt{\left(\sum_i x_i^2\right) - n\bar{x}^2}\sqrt{\left(\sum_i y_i^2\right) - n\bar{y}^2}}
$$
So you can accumulate 5 quantities:
$$ \hat{x} := \sum^n_{i=1} x_i \;\;\;\;\;\;\; \hat{y} := \sum^n_{i=1} y_i $$
$$ \hat{a} := \sum^n_{i=1} x_i^2 \;\;\;\;\;\;\; \hat{b} := \sum^n_{i=1} y_i^2 \;\;\;\;\;\;\; \hat{c} := \sum^n_{i=1} x_iy_i $$
And plug those into the formula whenever you want $r$. For completeness here it is with my terminology for accumulated values:
$$ r = \frac{\hat{c} - \frac{\hat{x}\hat{y}}{n}}{\sqrt{\hat{a} - \frac{\hat{x}^2}{n}}\sqrt{\hat{b} - \frac{\hat{y}^2}{n}}} $$
This will give you identical results to storing all the points and calculating $r$ at the end.
Note: The $\hat{x}^2$ terms can get very large, so to use this method, you might need to handle overflow.