Re: Return Statement Usage
- Posted by Irv <irv at ELLIJAY.COM> Jun 24, 1998
- 439 views
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