Quitting a program, without error
Author |
Message |
Alexander
|
Posted: Wed Sep 30, 2009 4:23 pm Post subject: Quitting a program, without error |
|
|
I'm past Turing, but it's always going to bug me how I never figured this out. Say I have a very complex program with lots of loops and procedures and processes. At one point in a procedure, in the main loop, the program needs to end. Exit the procedure, and the main loop. I used "quit" and worked but gave a quit error when the program closed, both compiled and un-compiled. I tried things like loop-if-loops, to attempt to make a conditional loop like "while" in Java, but it would let the loop finish first, and I didn't want that.
After that I wasn't so creative... I tried searching the Turing forums for an answer but the search for individual forum sections is broken, only the full site search works--and that yielded too many threads all over to weed out any answers. So, any solutions? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Wed Sep 30, 2009 4:40 pm Post subject: RE:Quitting a program, without error |
|
|
probably with a use of one or multiple return |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
jbking
|
Posted: Wed Sep 30, 2009 4:41 pm Post subject: Re: Quitting a program, without error |
|
|
There is a question of what kind of language you are using to some extent:
In C, C++, and C# there is a main function that is executed that is where the program execution happens and exiting that function terminates the program I believe.
Turing doesn't require any of this, just the basic flow of control through the lines of code provided. Could you write a one line "print 'Hello World!'" program in Turing and have it run? That's my suggestion for where to start and think carefully about why that would work or not. Not being familiar with Turing I merely present that as something to try and see what happens.
This is assuming you are running a program or application as there are a couple of other kinds of execution:
Web Pages/Applications - If you go to some page, the code execution may be a little different, e.g. in ASP.Net C# doesn't have a main but there are a number of functions within the Page Life Cycle
Services - If you want a long-running program, this doesn't necessarily have a common exit path unless something really bad happens.
|
|
|
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: Wed Sep 30, 2009 4:45 pm Post subject: RE:Quitting a program, without error |
|
|
Use return. |
|
|
|
|
![](images/spacer.gif) |
Alexander
|
Posted: Wed Sep 30, 2009 7:34 pm Post subject: Re: Quitting a program, without error |
|
|
jbking @ Wed Sep 30, 2009 4:41 pm wrote:
There is a question of what kind of language you are using to some extent:
...
... I'm posting in the Turing section, and talking about Turing.
To the others:
I've used return-- it'll return from the procedure to the loop, when I just want it to kill the process. It's a very conditional procedure and I can't weave it into the main loop (so that I could exit the main loop with it).
All in all, I just want it to simply stop all further code from being executed and close the window. Possible? |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: Wed Sep 30, 2009 7:42 pm Post subject: RE:Quitting a program, without error |
|
|
Well, you can have a universal boolean flag in every loop that says 'if flag = true then return' or whatever. |
|
|
|
|
![](images/spacer.gif) |
Alexander
|
Posted: Wed Sep 30, 2009 8:16 pm Post subject: Re: RE:Quitting a program, without error |
|
|
insectoid @ Wed Sep 30, 2009 7:42 pm wrote: Well, you can have a universal boolean flag in every loop that says 'if flag = true then return' or whatever.
When I initially tried that, I was only aware of exit, not return (which works for if statements too), so now my problem is solved! It sometimes takes a second or two to close, because it's a if statement in a procedure in a for statement in another procedure in a for statement in a loop. Yeah, really.
Anyways, thanks guys, these forums are so awesome and helpful. I'll upload my Asteroids game later today. |
|
|
|
|
![](images/spacer.gif) |
jbking
|
Posted: Thu Oct 01, 2009 9:24 am Post subject: Re: Quitting a program, without error |
|
|
Alexander @ Wed Sep 30, 2009 5:34 pm wrote: jbking @ Wed Sep 30, 2009 4:41 pm wrote:
There is a question of what kind of language you are using to some extent:
...
... I'm posting in the Turing section, and talking about Turing.
To the others:
I've used return-- it'll return from the procedure to the loop, when I just want it to kill the process. It's a very conditional procedure and I can't weave it into the main loop (so that I could exit the main loop with it).
All in all, I just want it to simply stop all further code from being executed and close the window. Possible?
I'm sorry for giving such a verbose answer but I think it may be useful to some. Maybe I should just not post in the Turing forums. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
|
|