Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Break out of IF statement and return to FOR loop + store the
Date: Wed, 6 Nov 2013 17:13:08 +0000 (UTC)
Organization: EDHEC Business School
Lines: 47
Message-ID: <l5dtb4$o8r$1@newscl01ah.mathworks.com>
References: <l5ajbf$lm8$1@newscl01ah.mathworks.com> <eb3bb20b-6880-49a2-88bf-dce38205d246@googlegroups.com> <l5ddgq$83q$1@newscl01ah.mathworks.com> <l5djc8$bd8$1@speranza.aioe.org> <l5djuu$d2s$1@speranza.aioe.org>
Reply-To: <HIDDEN>
NNTP-Posting-Host: rubyext-02-ls.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1383757988 24859 172.20.102.178 (6 Nov 2013 17:13:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 6 Nov 2013 17:13:08 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1690253
Xref: news.mathworks.com comp.soft-sys.matlab:804893

dpb <none@non.net> wrote in message <l5djuu$d2s$1@speranza.aioe.org>...
> On 11/6/2013 8:23 AM, dpb wrote:
> ...
> 
> > Need a second index as well is all...
> >
> > j = 1; k=0; % NB these alias the builtin Matlab i,j...
> > while j <= 100
> >   if condition is true
> >     do something
> >     B(j) = % store outputs
> >     j = j + 1;
> >   else
> >     do something else
> >     k=k+1;
> >     C(j) = B(i,:);
> >   end % if condition
> > end % while loop
> >
> ERRATA:
> 
>       C(j) = B(i,:);
> 
> is
> 
>       C(k) = B(j,:);
> 
> of course.  Also, it still will suffer as written w/ never getting past 
> that point because j ceases to be updated at that time.  The increment 
> for j needs to be outside the if...else...end block.
> 
> j = 0; k=0; % NB these alias the builtin Matlab i,j...
> while j <= 100
>    j = j + 1;
>    if condition is true
>      do something
>      B(j) = % store outputs
>    else
>      do something else
>      k=k+1;
>      C(k) = B(j,:);
>    end % if condition
> end % while loop
> 
> --

Thank you very much for the help and I will try it out!