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: for loop
Replies: 4   Last Post: May 13, 2013 4:37 PM

Advanced Search

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

Posts: 9,850
Registered: 6/7/07
Re: for loop
Posted: May 13, 2013 4:01 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 5/13/2013 2:17 PM, Tarik wrote:
> probably it is not understood properly...
> my expectation is that this codes calculate n(9) for l=0 and =1(both)
> hence the result would be ans =

>> 0 0 3
>> 0 3 0
>> 3 0 0

> and
>> ans =
>> 1 2 2
>> 2 1 2
>> 2 2 1

> but here I think for loop doesn't work properly
> but where is the problem...
> I hope someone can understand and help...
> (sorry for this confusion)


>> my problem is that both ans are in my expectation... I mean, for loop
>> doesn't work well here... it looks that it stops after a solution...
>> but why???
>> for l=0:sqrt(ni)
>> x=l;

if fix(y)==y
>> z=real(fix(sqrt(ni-x^2-y^2)));
if fix(z)==z
if ni==x^2+y^2+z^2;
>> n=[x,y,z];
>> end
>> end
>> end

Well, I've no idea what it is you're trying to describe as the result
but the reason the code will quit is the 'return' statement inside the
innermost if clause. If that IF... is ever satisfied, the RETURN will
then terminate the function at that point and (not surprisingly) return
to the calling routine or command line.

doc return

Perhaps you're looking for

doc break
doc continue




Date Subject Author
Read for loop
Read Re: for loop
Read Re: for loop
Read Re: for loop
Read Re: for loop

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.