Question:
I am learning c++, how do I break out of a infinite loop (i am using win Vista)?
Carla A
2011-08-16 13:34:12 UTC
Hi

I have been learning c ++ a couple of days...

I got my first inifinite loop (in command prompt) and nothing would break out of it

I tried : ctrl x , ctrl z , ctrl break , ctrl pause
I even tried Esc

can anyone help?
Twelve answers:
Guy
2011-08-17 07:46:28 UTC
you can put a condition in your programme to do this for you. Use the break statement in an if statement or a branch of an if statement to enable the loop to terminate after a certain amount of loops, use a variable that increments each time the loop compleats and when it is up to a certain point the condition/branch containing the break statement will terminate the loop. It's safer than risking memory leaks.



while(~infinite condition~)

{

if(~certainValue~ == ~certainCheckNumber~)

{

break;

}

}
peteams
2011-08-16 14:31:37 UTC
If you get an appilcation stuck in an endless loop in the command prompt and Ctrl+Break or Ctrl+C doesn't work, the simplest and safest thing to do is close the command prompt window.



Ctrl+Break and Ctrl+C will often fail if the application isn't reading or writing text to the console, which they often aren't if they are stuck.



To paste into the command prompt using the keyboard press Alt+Space to drop down the window menu and then select E for Edit then P for Paste. Ctrl+V doesn't work in the command prompt so it can remain compatible with really ancient applications.
Snic
2011-08-18 11:09:40 UTC
The [ X ] button in the upper right hand corner generally works for any exe stuck in a loop, it won't read any keys you press because the loop you have can never reach the ending expression, so it gets stuck, and can't compile any more code. To keep from getting infinite loops, you have to know what you're doing, and double check everything for mistakes. Make sure your expression can be met in all your loops. Hope this helps.
?
2016-10-19 08:23:38 UTC
i'm unsure what you mean by capacity of dosbox. in case you mean a Command instantaneous which you will run by capacity of typing in command after hitting the window key, all you're able to desire to do is click the X go out button on the appropriate good corner, like maximum homestead windows. i think of there is something stated as dosbox that helps you to run previous dos video games, wherein case i don't have a clue different than which you will kill procedures with the job supervisor by capacity of hitting ctrl alt del like the 1st answerer defined.
Puppere
2017-02-28 16:33:44 UTC
1
Asdfg
2014-02-08 08:30:08 UTC
Ctrl + m did it for me!
?
2011-08-17 10:24:28 UTC
Write the following code inside the loop which runs for infinte times.

char ch;

ch=getchar();

if(ch=='r')

{

break;

}

this will break the infinite loop when you press the key 'r' .

Remember to put this code inside the infinite loop:)

hope this helps:)
Leona
2011-08-16 19:26:05 UTC
Carla the infihet loop ?is an absolute maxime which is easer delt with in in the area of quatem physics E=mC sqrd it borders on the metaphysical plane..
2011-08-16 13:37:30 UTC
DO THIS:

Press control-alt-delete, (choose task manager), click the applications, right click on your program, go to process, then right click on THE HIGHLIGHTED PROCESS, and click end process.



ADDITIONAL:

If you are using an IDE such as Netbeans or Visual Studio, and are debugging, you can kill it from the IDE by clicking a stop-like button, but it varies from IDE to IDE.
SomeGuy
2011-08-16 13:39:24 UTC
control + alt + delete to bring up the task manager and end the process



Hope This Helped :D
HMJava
2011-08-16 13:35:15 UTC
CTRL + C
2014-03-17 10:37:08 UTC
u can press ctrl+del....


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...