Re: Returning within a Number of Functions



On Sep 10, 4:11 pm, "David " <d...@xxxxxxxxxxxxxx> wrote:
LindsE <LindsEHill...@xxxxxxxxx> wrote in message <b312b9fe-54bf-4e87-a0be-7bc445129...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
On Sep 10, 3:38=A0pm, "David " <d...@xxxxxxxxxxxxxx> wrote:
LindsE <LindsEHill...@xxxxxxxxx> wrote in message <d1b44d0a-5822-4a2d-bd8=
5-ca73abd32...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>...
Hi there;

I have a series of several functions running within a large loop and
would like Matlab to proceed to the next value in the loop if a
certain condition exists.

For example:

I run a calling function that calls about 15 - 20 other functions
within a loop (111 iterations). Within function #12, if a variable =3D
0, I want Matlab to stop the iteration and return to the calling
function taking the next iteration and running until the condition is
met again.

Is there a function that can do this? Right now I'm using:
=A0 =A0 =A0 =A0 warning('Required data may be out of grid''s bounds')
=A0 =A0 =A0 =A0 dbstop if warning

but that won't allow the function to continue with the next
iteration. =A0Is it possible to use a "try"/"catch" such that:

try
=A0value ~=3D0
catch
=A0 return to calling function
end

or something similar?

I hope I have provided ample detail!

Thanks;
Lindsay

how about just

if (value~=3D0)
=A0 return
end

Will 'return' bring me back to the calling function?  I tried it
before but perhaps I made a typo as it didn't seem to work.

if i am reading your word description it should... maybe you should cut down some code as an example... what i think you are saying is

function loopfunction()

for x=1:111
  callingfunction()
end

function callingfunction()
  function1()
  function2()
...
  a=function12();
  if (a~=0)
    return
  end
...

now it could be that you are calling all the functions right in the loop and just want to skip to the next iteration, that would use the continue function like this:

for x=1:111
  function1()
  function2()
...
  a=function12();
  if (a~=0)
    continue
  end
...
  function20()

end

in this case when you hit your condition the continue statement skips to the end of the for loop and does the next iteration.

Hi, David;

The second example is closer, but still not quite it. Let me explain
using your example:

for x=1:111
function1()
function2()
...
a=function12();
if (a~=0)
continue
end
...
function20()

end

Where you use continue and function20() is called, I wish to return to
within the loop and call function1() again as each looped iteration
uses different data but the same functions.

Does this make any sense to you?

Thanks;
Lindsay
.



Relevant Pages

  • Re: For Next with negative step ?
    ... 'lPos sets row position, and is used to calc the left side of result. ... the number of columns for each iteration of the loop that follows. ...
    (microsoft.public.excel.programming)
  • Re: LOOP blows!
    ...     clauses appear in the source. ... This clause is not combined with the ... Right, and ``People'' includes the ones implementing LOOP, apparently, ... You must use your hidden list iteration variable to set up the ...
    (comp.lang.lisp)
  • Re: Returning within a Number of Functions
    ... within a loop. ... I want Matlab to stop the iteration and return to the calling ... function taking the next iteration and running until the condition is ...
    (comp.soft-sys.matlab)
  • Re: Better mehod to generate a sequence of range?
    ...     (loop for i from n to m ... (defun range (n m) ... There is nothing wrong using normal iteration using LOOP like above. ...
    (comp.lang.lisp)
  • Re: Better mehod to generate a sequence of range?
    ...     (loop for i from n to m ... If the compiler is in a non-TCO mode or does not support TCO you may ... There is nothing wrong using normal iteration using LOOP like above. ...
    (comp.lang.lisp)