Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.


Curious
Posts:
2,359
Registered:
12/6/04


Re: Variables outside a while loop
Posted:
Mar 7, 2014 4:45 PM


"jimmy bodo" wrote in message <lfd43r$opj$1@newscl01ah.mathworks.com>... > In the code below > > for r=7:15 > for s=15:22 > > total=1; > > while(i<=...) > > operations on total > > end > i=i+1; > end > > record(s)=total > end > final(r)=max(total) > > why is it that all the values in record and final are 1. shouldn't the value of total be updated?
Don't you want
i=i+1
INSIDE the while loop?
BTW, its a good idea to avoid using i (and j) as an index since it is used by MATLAB as the sqrt(1)? Sooner or later this nuance is going to bite you.



