
-----------------------------------
Tallguy
Tue May 05, 2009 8:54 am

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..


proc main
%code
exit if /*something = true*/
end main


any ideas?

-----------------------------------
[Gandalf]
Tue May 05, 2009 9:07 am

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
Tue May 05, 2009 9:29 am

Re: Exit statement for procedures
-----------------------------------
what i mean is in using an recusive programing where the procedures calls itself to run such as 


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
Tue May 05, 2009 9:59 am

Re: Exit statement for procedures
-----------------------------------

if /*condition*/ then
    return
else
    %call procedure again
end if


-----------------------------------
[Gandalf]
Tue May 05, 2009 10:25 am

RE:Exit statement for procedures
-----------------------------------
Or rather:
[code]proc ...
    if box not certain size then
        current body of proc
    end if
end ...[/code]
You really shouldn't use return when you're not explicitly returning something, as in a function.

-----------------------------------
Dusk Eagle
Tue May 05, 2009 2:46 pm

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
Tue May 05, 2009 3:53 pm

Re: RE:Exit statement for procedures
-----------------------------------
Or rather:


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]
Tue May 05, 2009 4:02 pm

Re: RE:Exit statement for procedures
-----------------------------------
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.

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.

-----------------------------------
BigBear
Tue May 05, 2009 10:02 pm

RE:Exit statement for procedures
-----------------------------------
A procedure will follow through the code and leave the procedure

-----------------------------------
Insectoid
Wed May 06, 2009 10:36 am

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
[/code]
