1. Return Statement Usage

I have two questions about the return statement.

1.   If I have a main program, and I call a global procedure within an
include file, do I need to put return at the end of the global procedure?=


2.  In the same set of procedures, in the global procedure, which is in t=
he
include file, I call a local procedure that is in the same include file. =

Do I need to put return at the end of the local procedure to continue wit=
h
the main procedur?

In general, under what circumstances should one use return at the end of =
a
procedure to keep the program from "wandering off"?

--Alan
 =

new topic     » topic index » view message » categorize

2. Re: Return Statement Usage

In all situations the end of procedure returns to the calling point.
(Wherever that was.) If you called a global, then it returns to where you
called it from. If you call a local, that procedure would return to the
point from which it was called.

While I do not know the internals of Euphoria, I suspect the return address
is pushed onto a stack that is LIFO. That is, last one on the stack is the
first one off. This would allow the program to always know "..from whence
it came."   I also suspect an end of procedure actually executes a return
statement.

The exception is code in an include file that is not within a procedure,
that would run at program start and fall down to whatever other code was
not in a procedure. (ie - your actual main loop somewhere in your program.)
 However, you would never be able to "call" that "renegade'" code as it has
no entry point.  [ Actually, you COULD call it renegade code, I don't think
any one would care ! ]


At 10:53 PM 6/23/98 -0400, you wrote:
>I have two questions about the return statement.
>
>1.   If I have a main program, and I call a global procedure within an
>include file, do I need to put return at the end of the global procedure?
>
>2.  In the same set of procedures, in the global procedure, which is in the
>include file, I call a local procedure that is in the same include file.
>Do I need to put return at the end of the local procedure to continue with
>the main procedur?
>
>In general, under what circumstances should one use return at the end of a
>procedure to keep the program from "wandering off"?
>
>--Alan
>
>

 Joe Phillips, Assistant Director
 Information Technology Services
 Texas Wesleyan University     817-531-4284

new topic     » goto parent     » topic index » view message » categorize

3. Re: Return Statement Usage

Alan Tu wrote:

> I have two questions about the return statement.
>
> 1.   If I have a main program, and I call a global procedure within an
> include file, do I need to put return at the end of the global procedure?
>

Never use  return in a procedure. A procedure does a job (procedure) and
returns by itsel.f.Always use a return at the end of a function. (A function
must return somthing to it's caller.)

Procedures do stuff until they hit the "end procedure" statement,
while functions can return before they get to the "end function",
A function can have several "return" statements, based on different tests:

function avg_days_pay (atom weekly_pay, atom days_worked)
if days_worked < 1 then return 0 -- can't divide by zero, so answer would be
meaningless
else return weekly_pay / days_worked
end if
end function

> 2.  In the same set of procedures, in the global procedure, which is in the
> include file, I call a local procedure that is in the same include file.
> Do I need to put return at the end of the local procedure to continue with
> the main procedur?
>
> In general, under what circumstances should one use return at the end of a
> procedure to keep the program from "wandering off"?
>
> --Alan

new topic     » goto parent     » topic index » view message » categorize

4. Re: Return Statement Usage

Irv wrote:

> Never use return in a procedure. <snip>

According to Robert, the use of return statements as alternative exit
points from procedures has been, and always will be supported. It is a
very handy feature, e.g. in certain kinds of recursion. Jiri

new topic     » goto parent     » topic index » view message » categorize

5. Re: Return Statement Usage

-----Original Message-----
De: Irv <irv at ELLIJAY.COM>
Para: EUPHORIA at cwisserver1.mcs.muohio.edu
<EUPHORIA at cwisserver1.mcs.muohio.edu>
Fecha: miércoles 24 de junio de 1998 1:06
Asunto: Re: Return Statement Usage


>Never use  return in a procedure. A procedure does a job (procedure) and
>returns by itsel.f.Always use a return at the end of a function. (A
function
>must return somthing to it's caller.)

>Procedures do stuff until they hit the "end procedure" statement,
>while functions can return before they get to the "end function",
>A function can have several "return" statements, based on different tests:

A procedure can also have several "return" statements. The only thing is
that a procedure can't return a value. It's ilegal to say: return foo,
within a procedure. Having return statements inside procedures is quite
useful indeed.

Regards,
    Daniel   Berstein
    daber at pair.com

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu