The Math Forum

Search All of the Math Forum:

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

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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 ]

Posts: 2,359
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$>...
> 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


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]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.