Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Variables outside a while loop
Replies: 3   Last Post: Mar 7, 2014 10:08 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Curious

Posts: 2,005
Registered: 12/6/04
Re: Variables outside a while loop
Posted: Mar 7, 2014 4:45 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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.



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.