Re: Hi

new topic     » goto parent     » topic index » view thread      » older message » newer message

Thanks for the message,

Um, about using the return statment, could I write a procedure and simply put
return( ) on the last line before end procedure and this would return the
program
to the if-then or whatever else that had called it?

Thanks!
Ken Furlong smile


Daniel Berstein wrote:

> >Could I write my own procedure and then use it like gosub except of course
> for
> >including the variable values in the ( ) when I call it.  Wouldn't this work
> >basically the same way with an if-then?
> >
> >i.e.  -
> >
> >if var1 = 1
> >then my_procedure(*,*,*)
> >
> >etc.....
>
> You can do that, but once my_procedure finish the execution will continue
> on the
> next statement of the calling routine!
>
> What I understood was that you wanted something like:
>
> procedure silly_test_procedure()
>         [...]
>         if a = b then
>                 if c = d then
>                         if f = g then
>                                 jump_to CONTINUE
>                         else
>                                 [...]
>                         end if
>                 end if
>         end if
>         [...]
> CONTINUE:
>         [...]
> end procedure
>
> This *can't* be done with Euphoria. You're try was:
>
> procedure two()
>         [...]
> end procedure
>
> procedure one()
>         [...]
>         if a = b then
>                 if c = d then
>                         if f = g then
>                                 two()   -- Won't help
>                         else
>                                 [...]
>                         end if
>                 end if
>         end if
>         [...]
> end procedure
>
> What you *can* do is exit a procedure before it reaches the "end procedure"
> with the "return" statement. You should modularize your code into simpler
> routines and call them consecuently with the expected runtime flow of the
> program.
>
> Also (as an advanced Euphoria programming technique) you can use the
> "routine_id" and "call_proc"/"call_func" to perform dynamic code execution
> based on runtime events.
>
> Block labeling is mostly used for exiting deeply nested code, try to avoid
> such coding where possible. A smart use of if..then..else and choosing the
> right code for the right routines will help you get out of these
> situations. As I said before, when in trouble post your code, 230+
> programmers think better than one ;)
>
> Saludos,
>         Daniel   Berstein
>         daber at pair.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu