Exit statement for procedures
Author |
Message |
Tallguy
|
Posted: 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..
Turing: |
proc main
%code
exit if /*something = true*/
end main
|
any ideas? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
[Gandalf]
|
Posted: 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. |
|
|
|
|
|
Tallguy
|
Posted: 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
Turing: |
setscreen ("graphics:500,500") %set screen to a specfic size
proc draw (x, y, x2, y2 : int) %declares a proc with prameters
drawbox (x, y, x2, y2, 12) %Draw the box
delay (500)
draw (x + 10, y + 10, x2 - 10, y2 - 10) %recursion re-call proc to run
end draw
draw (10, 10, 490, 490) % calls the proc to run
|
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? |
|
|
|
|
|
Dusk Eagle
|
Posted: Tue May 05, 2009 9:59 am Post subject: Re: Exit statement for procedures |
|
|
Turing: |
if /*condition*/ then
return
else
%call procedure again
end if
|
|
|
|
|
|
|
[Gandalf]
|
Posted: Tue May 05, 2009 10:25 am Post subject: RE:Exit statement for procedures |
|
|
Or rather:
code: | proc ...
if box not certain size then
current body of proc
end if
end ... |
You really shouldn't use return when you're not explicitly returning something, as in a function. |
|
|
|
|
|
Dusk Eagle
|
Posted: 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. |
|
|
|
|
|
Euphoracle
|
Posted: 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:
code: | proc ...
if box not certain size then
current body of proc
end if
end ... |
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. |
|
|
|
|
|
[Gandalf]
|
Posted: 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. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
BigBear
|
Posted: 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 |
|
|
|
|
|
Insectoid
|
Posted: 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.
code: |
%instead of
proc bleurgh
put "Blablabla"
exit bleurgh when foo = baz
bleurgh
end beurgh
%do
proc bleurgh
put "Blablabla"
if foo ~= baz then %"~=" is the same as "not equals" or "!=" (!= will not work in Turing)
bleurgh
end if
end bleurgh
|
|
|
|
|
|
|
|
|