Jump to content
  • Advertisement
Sign in to follow this  
orcfan32

Exiting program from code?

This topic is 4868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
depends how you want to do it really, if your program has no loop or getch() etc then it will exit itself, but more info is needed really

Share this post


Link to post
Share on other sites
Well, there is the exit() function, that will force your program to quit, but calling it from deep within the program is dangerous (there are some catches involved, because it doesn't unwind the stack). If at all possible, you should try to exit via returning from main, either by using return codes to flag errors (simple but crude) or by using structured exception handling (more sophisticated, but trickier to design with).

If you want to get out of the middle of a loop, you can simply issue the break; statement, and it will jump out to whatever comes after the loop.

Share this post


Link to post
Share on other sites
You can use a bool like this. If you set the bool to false from within the loop, the program will exit.


int main()
{
//set up variables etc.
bool b_continue;
while(b_continue)
{
//do stuff
}
//free memory
return 0;
}

Share this post


Link to post
Share on other sites
Quote:
Original post by Promit
If you want to get out of the middle of a loop, you can simply issue the break; statement, and it will jump out to whatever comes after the loop.


That's the problem: I have text to print after the loop if all conditions are met, and I don't want to break from the loop and print that text to the console.

Share this post


Link to post
Share on other sites
Then you need to restructure your code. Show us what you have and I'll try to give you some helpful pointers.

But for a quick and dirty way to get what you want, you could break out of the loop using return, which would avoid your loop exit code.

Share this post


Link to post
Share on other sites
Quote:
Original post by Nitage
Then you need to restructure your code. Show us what you have and I'll try to give you some helpful pointers.


Sorry, no can do.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!