[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A "cycle" command for octave ?
From: |
Andrass Ziska Davidsen |
Subject: |
Re: A "cycle" command for octave ? |
Date: |
Tue, 13 Sep 2005 17:32:15 +0200 |
On Tue, 2005-09-13 at 11:10 -0400, Madhusudan Singh wrote:
> Hi
>
> I know that Matlab does not seem to offer this functionality, but I was
> wondering if a future version of octave could include the equivalent of a
> Fortran 95 cycle command ?
>
> Basically what it does is go to the next iteration in a for or a while loop :
I believe you want the 'continue' statement. See `help -i continue` at
your Octave prompt.
> Fortran 95 :
>
> do i = 1,10
> if (f(a,i).eq.0.0) cycle
> ...
> ...
> ...
> enddo
>
> where f is a function and a is any argument.
>
> I know it is possible to replicate this functionality by using an if-else
> block, but that sphaggetizes the code if the loop is very long and
> complicated.
You could also negate your if and enclose all of the loop's innards in
that if block.
Something like:
for i = 1:10
if (f(a,i)~=0.0)
...
...
...
endif
endfor
(Sorry, I don't know the corresponding Fortran syntax.)
--
Andrass Ziska Davidsen
M.Sc. Offshore Construction
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------