Computer Science Canada Exit statement for procedures  | 
  
| Author: | Tallguy [ Tue May 05, 2009 8:54 am ] | ||
| Post subject: | Exit statement for procedures | ||
i'm wondering if its possible to exit a procedure that doesn't have any conditional or normal loops in it. such as.. 
 any ideas?  | 
	|||
| Author: | [Gandalf] [ Tue May 05, 2009 9:07 am ] | 
| Post subject: | RE:Exit statement for procedures | 
Usually you just let the procedure evaluate to the end, and then it 'exits' on its own. If you need to prematurely exit, you could use a empty return statement... Though this shouldn't really be necessary.  | 
	|
| Author: | Tallguy [ Tue May 05, 2009 9:29 am ] | ||
| Post subject: | Re: Exit statement for procedures | ||
what i mean is in using an recusive programing where the procedures calls itself to run such as 
 and lets say you want the program to stop when the box is a certain size, to exit, not using any type of loop...any ideas?  | 
	|||
| Author: | Dusk Eagle [ Tue May 05, 2009 9:59 am ] | ||
| Post subject: | Re: Exit statement for procedures | ||
  | 
	|||
| Author: | [Gandalf] [ Tue May 05, 2009 10:25 am ] | ||
| Post subject: | RE:Exit statement for procedures | ||
Or rather: 
 You really shouldn't use return when you're not explicitly returning something, as in a function.  | 
	|||
| Author: | Dusk Eagle [ Tue May 05, 2009 2:46 pm ] | 
| Post subject: | Re: Exit statement for procedures | 
Yes, but since he specifically asked for it, I showed how it worked. I agree that you should avoid preemptively ending your procedures like above.  | 
	|
| Author: | Euphoracle [ Tue May 05, 2009 3:53 pm ] | ||
| Post subject: | Re: RE:Exit statement for procedures | ||
Gandalf @ Tue May 05, 2009 10:25 am wrote: Or rather:
 
 You really shouldn't use return when you're not explicitly returning something, as in a function. Return isn't for returning a value in turing, result is. Return is for terminating a procedure prematurely. Alternatively, you could simply not call the procedure again by checking whether or not it will be done at that stage.  | 
	|||
| Author: | [Gandalf] [ Tue May 05, 2009 4:02 pm ] | 
| Post subject: | Re: RE:Exit statement for procedures | 
Euphoracle @ 2009-05-05, 3:53 pm wrote: Return isn't for returning a value in turing, result is.  Return is for terminating a procedure prematurely. 
My bad, I'd forgotten. Nevertheless, the same hold true for its use. There's no reason to be using return, in this situation or pretty much any other. It's like going back to goto... You could, but it's only going to make your code sloppier. Euphoracle @ 2009-05-05, 3:53 pm wrote: Alternatively, you could simply not call the procedure again by checking whether or not it will be done at that stage. 
Yes, this is what I mentioned.  | 
	|
| Author: | BigBear [ Tue May 05, 2009 10:02 pm ] | 
| Post subject: | RE:Exit statement for procedures | 
A procedure will follow through the code and leave the procedure  | 
	|
| Author: | Insectoid [ Wed May 06, 2009 10:36 am ] | ||
| Post subject: | RE:Exit statement for procedures | ||
The idea is not to end the procedure via a conditional, but to use a conditional to keep it going. It will naturally end then if the conditional returns false. 
  | 
	|||