MATLAB: Saving the last value of a loop that will run 100 times

for looploopwhile loop

I have a function x that is dependent on a random variable s, where s =randn(1,1) the function x=x+s , where x will be replaced by the new value everytime the loop runs i need to create a loop script that when x is less/equal to -10 or more/equal to 10, it will stop and calculate how many times the loop has ran. I then need to run this loop in a loop 100 times and calculate the average number of times the loop ran to hit the 10/-10 condition in a total of 100 times. My script looks like this with alot missing:
x=0;
step=0;
while (x<10)&&(x>-10)
s=randn(1,1);
x=x+s;
step=step+1
end

Best Answer

step = zeros(100,1);
for k=1:100
x=0;
step_actual=0;
while (x<10)&&(x>-10)
step_actual = step_actual+1;
s=randn(1,1);
x=x+s;
end
step(k)=step_actual;
end
step_mean = mean(step);