0
$\begingroup$

I have a simple while loop. After running, the variable does not change:

a=1;
b=2; 

v1 = NSolve[a^2 == E^(-(x/b))/x, x, Real][[1]];
f[x_] := x;
v = f[x /. v1]
v=5.72178

I use above value of v as intial value of v in the while loop:

i = 1; v = f[x /. v1];
While[ i < 10, v = v++; i++]

Now, I want to see what is the value of "i" and "v" after running while loop:

?i
i=10

but v is not changed:

?v
v=5.72178

why "v" doesn't change? What should I do?

$\endgroup$
  • 3
    $\begingroup$ Either v++ or v=v+1. Not both. $\endgroup$ – AccidentalFourierTransform Jun 27 at 23:10
  • $\begingroup$ Or v=++v if you insist on horrible syntax. This is a good opportunity to learn about what ++v and v++ really mean: pre-increment and post-increment. $\endgroup$ – Roman Jun 28 at 5:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.