How can I find the value of the expression $\sqrt{2}^{\sqrt{2}^{\sqrt{2}^...}} $? I wrote a computer program to calculate the value, and the result comes out to be 2 (more precisely 1.999997). Can anyone explain what's happening? Is there any general method to calculate these expressions? I am new to these problems.Thanks in advance!
EDIT On looking at the answer by Clement C., I thought I could generalize the method to find the value of any expression of the form $\sqrt[n]{n}^{\sqrt[n]{n}^{\sqrt[n]{n}^...}} $. The value should be $n$, but this is not the case. This is the graph for $n<50$.

Any help would be appreciated.
We don't allow infinite expressions, so first you need to define what it means. One way to make sense of it is as a sequence, $a_1=\sqrt 2, a_2 =\sqrt 2 ^{\sqrt 2}, a_3=\sqrt 2 ^{\sqrt 2^{\sqrt 2}},a_n=\sqrt 2^{a_{n-1}}$ and ask if the sequence has a limit as $n \to \infty$ If the limit exists, call it $L$. Then $L=\sqrt 2^L$, which is satisfied by $2$. To prove the limit exists, show that $a_n \lt 2 \implies a_{n+1} \lt 2$ and $a_n \gt 1 \implies a_{n+1} \gt a_n$. The sequence is now monotone and bounded above, so has a limit.