Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Quitting a program, without error
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Alexander




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Sep 30, 2009 4:40 pm   Post subject: RE:Quitting a program, without error

probably with a use of one or multiple return
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
jbking




PostPosted: 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.
DemonWasp




PostPosted: Wed Sep 30, 2009 4:45 pm   Post subject: RE:Quitting a program, without error

Use return.
Alexander




PostPosted: 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?
Insectoid




PostPosted: 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.
Alexander




PostPosted: 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.
jbking




PostPosted: 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.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: