Computer Science Canada

A better way then QUIT?

Author:  S_Grimm [ Wed Apr 30, 2008 11:54 am ]
Post subject:  A better way then QUIT?

Alright. I know that there must be a better way to exit a Turing Program than "quit", but I don't know it. Can anyone else perhaps, inform me what it is? (If I'm not crazy and a way does exist.)

Author:  Clayton [ Wed Apr 30, 2008 11:58 am ]
Post subject:  RE:A better way then QUIT?

Have no more code to run. So exit your main loop such that there is no more code to run afterward.

Author:  petree08 [ Wed Apr 30, 2008 12:08 pm ]
Post subject:  RE:A better way then QUIT?

Window.Close (WinID) - F9 it

Author:  Tony [ Wed Apr 30, 2008 3:22 pm ]
Post subject:  Re: RE:A better way then QUIT?

petree08 @ Wed Apr 30, 2008 12:08 pm wrote:
Window.Close (WinID) - F9 it

that's a better way to exit the program, how?

Author:  Sean [ Wed Apr 30, 2008 3:25 pm ]
Post subject:  RE:A better way then QUIT?

Window.Close just closes the created window and cancles, however I doubt that is what they wanted.

Author:  darkangel [ Wed Apr 30, 2008 3:26 pm ]
Post subject:  Re: A better way then QUIT?

code:
return

also works, it stops the program dead in its tracks.

Author:  Sean [ Wed Apr 30, 2008 3:30 pm ]
Post subject:  RE:A better way then QUIT?

Or if it is in a loop, and something happens use

code:

exit

Author:  syntax_error [ Wed Apr 30, 2008 4:34 pm ]
Post subject:  RE:A better way then QUIT?

I truly detest the teaching of exit as the only way to get out of a loop, the best way taht should be taught is meeting the condition of the loop. no?

Author:  S_Grimm [ Thu May 01, 2008 10:25 am ]
Post subject:  RE:A better way then QUIT?

Sorry, I should have been more specific. The code goes something like this:

CODE

if (i = "yes") then
QUESTIONS %Procedure that has been predefined%%%
end if
if (i = "no") then
quit ************* This is the part I want to change
end if

END CODE

ther are about 2 loops ahead of this statement, and exit didn't work (i tried)

Author:  Clayton [ Thu May 01, 2008 11:17 am ]
Post subject:  Re: RE:A better way then QUIT?

syntax_error @ Wed Apr 30, 2008 4:34 pm wrote:
I truly detest the teaching of exit as the only way to get out of a loop, the best way taht should be taught is meeting the condition of the loop. no?


Ummm... Let's say you have some condition that you need to obtain in a loop for exit:

code:

loop
    exit when [condition]
end loop


This is fine. But what if some form of computation needs to occur after that condition is true? Our code would now look like this:

code:

loop
    if [condition] then
        <computation>
        exit
    end if
end loop


In fact, the first code block is just syntactical sugar for:
code:

if [condition] then
    exit
end if


So what's the problem?

Author:  petree08 [ Thu May 01, 2008 11:23 am ]
Post subject:  RE:A better way then QUIT?

what i mean by Window.Close is that after the program is done it closes the window.

I figured he wanted to know how to get the program to close the wnidow after the program.

Author:  S_Grimm [ Thu May 01, 2008 11:40 am ]
Post subject:  RE:A better way then QUIT?

I need to complete close the program if the answer is wrong. if it is right, the program goes on.

Author:  Prince Pwn [ Thu May 01, 2008 12:19 pm ]
Post subject:  RE:A better way then QUIT?

I don't have Turing with me but I know what you mean. It goes something like this:

% instead of View.Set at the top of your program, do:
var winID := Window.Open("graphics;400:500")

% at the bottom
Window.Close(winID)

If you compile your program into an exe, you can check a box to "close program when finished".

I know you can get it to close somehow, I did it before. If none of that works then keep trying something like that.

Author:  Sean [ Thu May 01, 2008 2:09 pm ]
Post subject:  Re: A better way then QUIT?

He never once ment closing a window. As said before, he needs to exit or return as one of his conditions.

If your code is in a loop, which it should be then:

Turing:


if i = "Yes" or i = "yes" then
     %Code
else
     exit
end if

Author:  S_Grimm [ Mon May 05, 2008 10:51 am ]
Post subject:  Re: A better way then QUIT?

Yes it's in a loop. nestled within a loop so it's like this
code:

loop
%More code above this
    get answer
loop
if answer = "yes" or answer = "Yes then
exit
elsif answer = "no" or answer = "No" then
       quit  %I need to change this
elsif answer not= "Yes" or answer not= "yes" or answer not= "no" or answer not= "No" then
put "Incorect input. Please Re-Enter : "..
get answer
end loop
%more code
end loop


My problem is the second loop, the one for the entire program. "exit" will only exit the second loop, not the first loop. I need a way to exit BOTH loops at once.

Author:  petree08 [ Mon May 05, 2008 11:08 am ]
Post subject:  RE:A better way then QUIT?

code:

var Quit : boolean
loop
%More code above this
    get answer
loop
if answer = "yes" or answer = "Yes then
Quit := true
exit
   
elsif answer = "no" or answer = "No" then

elsif answer not= "Yes" or answer not= "yes" or answer not= "no" or answer not= "No" then
put "Incorect input. Please Re-Enter : "..
get answer
end loop
%more code
exit when Quit
end loop



I can't believe you had to ask that

Author:  Carey [ Mon May 05, 2008 1:26 pm ]
Post subject:  RE:A better way then QUIT?

or you could just use return. return is usually used to get out of a procedure. if you call it when you are not in the middle of a procedure, it ends the program. If you have any questions PM me.

Author:  S_Grimm [ Fri May 09, 2008 11:50 am ]
Post subject:  RE:A better way then QUIT?

thanks everyone


: