how do u make a loop that will stop when u hit a key
ex.kbhit(); :confused:
Printable View
how do u make a loop that will stop when u hit a key
ex.kbhit(); :confused:
what kind of loop are you wanting to use?
//i want a loop like this to be stoppded when hit key
//anybody who knows, please help me!
#include <iostream.h>
int main()
{
int x;
for(x=0;x<100000;x++)
cout<<x;
return 0;
}
This is what you would do and how you would do it:
Does this help?Code:while (!kbhit())
{
/*** do whatever you have to do ***/
}
--Garfield
well you may want to use an if statement and a function that always gets a keystrok, and execute the if statement if a key is pressed. then you could have it x=100000, and that would stop it. you could also use the while loop suggested, but you would want to limit it by using a counter and another condition to the loop
>> but you would want to limit it by using a counter and another condition to the loop <<
Why???
he has a for loop, it will end after a period of time, so if he wanted it to still do that, he would need a counter and an additional condiditon that includes the counter
But why would you need a "limit"?
I don't know, it is his code, but he had one in his example, so he will probably want one