# Loop doesn't hold the value

My program doesn't hold the value in a variable as I want it. I want to attach the calculated value as a list in a variable. What is wrong here?

t = 10
While[t >= 1,
sw = 30^2*(StandardDeviation[x]/Sqrt[11 - t])^2 + 10^2*(StandardDeviation[y]/Sqrt[t])^2;
t = t - 1];

• Why would sw = Table[30^2*(StandardDeviation[x]/Sqrt[11 - t])^2 + 10^2*(StandardDeviation[y]/Sqrt[t])^2, {t, 10, 1, -1}] not work? – J. M.'s discontentment Oct 11 '18 at 18:45
• hmm It works properly but, how would i do it as as loop? – hcp Oct 11 '18 at 18:48
• Easy: don't.. – AccidentalFourierTransform Oct 11 '18 at 19:55

J.M. and AccidentalFourierTransform have already shown you the standard answer in the comment, but if you still insist on making your loop work, you can use the following:

Clear@sw
sw = {}; (sw = a_) ^:= (sw := #) &[sw~Join~{a}]

t = 10
While[t >= 1,
sw = 30^2 (StandardDeviation[x]/Sqrt[11 - t])^2 + 10^2 (StandardDeviation[y]/Sqrt[t])^2;
t = t - 1]

sw == Table[
30^2 (StandardDeviation[x]/Sqrt[11 - t])^2 + 10^2 (StandardDeviation[y]/Sqrt[t])^2, {t,
10, 1, -1}]
(* True *)


try this then..

t = 10;
s = {};
While[t >= 1,
sw = 30^2*(StandardDeviation[x]/Sqrt[11 - t])^2 +
10^2*(StandardDeviation[y]/Sqrt[t])^2; AppendTo[s, sw];
t--];
s