Path: news.mathworks.com!newsfeed-00.mathworks.com!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: for loop
Date: Mon, 13 May 2013 15:03:14 -0500
Organization: Aioe.org NNTP Server
Lines: 59
Message-ID: <kmrgt1$8on$1@speranza.aioe.org>
References: <kmqq4f$dpf$1@newscl01ah.mathworks.com> <kmre7n$mk0$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: 9UH+qIE/vu9qp97Eh5PBMQ.user.speranza.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20
X-Notice: Filtered by postfilter v. 0.8.2
Xref: news.mathworks.com comp.soft-sys.matlab:795469

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;
      y=real(fix(sqrt(ni-x^2)));
      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];
            result=unique(perms(n),'rows');
            return
          end
>>     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

mayhaps???

--


--