I remember this part but I can't just figure it out.. My current code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* Make a program that keeps printing the multiples of the integer 2. */
#include <iostream>
usingnamespace std;
int main()
{
int total;
while(true)
{
cout << " " << total << endl;
total*2;
}
return 0;
}
Bufflez, that happens because you close the terminal before it gets a chance to load the program, the terminal processes is still active, you need to kill it through a task manager, then you re-run it.
I use infinite loops frequently, just breaking out of them when I need to, it's better than goto and uses less memory than if I had some arbitrary bool value for every while loop.
that happens because you close the terminal before it gets a chance to load the program, the terminal processes is still active
This just doesn't happen. Closing the console terminates the program running on it. I believe the program gets a SIGINT to get a chance to quit cleanly.
Code::Blocks is a special case because it doesn't run the program directly. You'll notice that at the end it displays its run time and waits for a key press. The regular console doesn't do this. What Code::Blocks does is run a program that itself runs the user's program. Now, what happens to the child process, I have no clue.
Zephilinox, if you 'x' out a running program in Code::Blocks in debug mode, it is still "debugging". To stop the debug process, you need to "abort" it. It's on the line where there is also a button for "compile" and "run" and such.
Aborting usually doesn't work for me, and by debug mode do you mean in contrast with release? or as in actually using a debugger? because I don't use debuggers that often.
you can either do what I suggested, and kill it via a terminal or gui application (in Windows 7 press ctrl-shift-esc, click processes tab, find program, end process), bools suggestion of pressing abort (which hasn't worked for me in the past, but may for you) or as a last resort restart your PC.
It is not a simple task as it seems at the first glance. Below is the corresponding code. I restricted the range of values to the type char because for the int type the output will be too big.
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
#include <limits>
int main()
{
for ( char i = 1; i < std::numeric_limits<char>::max(); i++ )
{
if ( ( i + 1 & 1 ) == 0 ) std::cout << i + 1 << ' ';
}
return ( 0 );
}