Community RSS Feed
http://community.wolfram.com
RSS Feed for Wolfram Community showing any discussions in tag Wolfram Training sorted by activeHelp making Conditional Statement work in a Loop
http://community.wolfram.com/groups/-/m/t/1524218
I am a beginner in running small simulations in Mathematica and I am trying to code a loop to compute the expected value of a piecewise function. To do so, I am trying first to make a conditional statement work inside a loop, without success.
I cannot make the conditional statement work inside the loop, which seems silly. In the code, the variable j can be either higher or lower than 3, but the output of the conditional statement in the code does not vary for different values of j. Can someone pinpoint the error? Thanks!
n=10;
For[z = 0; j = 1, j < n + 1, j++,
Print[j];
z = RandomVariate[NormalDistribution[0, 1], n];
if[j < 3, x = j, x = 0]; Print[x];
]Maria Bustamante2018-10-20T14:44:29Z