do something while input isn't 5..

I want to keep looping in a while loop until the user presses the value 5, but the function cin shouldn't block the while loop...

ex:
1
2
3
4
5
6
7
8
int t;
do
{
   custom_function(int)
   cout << "am i Done" << endl;
   cin >> t;
}
while(t!= 5)

The problem here is that the custom_function(int) only run once, since cin>>t blocks further actions..

I want to keep running the custom_function(int), until i the user insert the number 5.. how do i do that?
Last edited on
Cant you just put it above custom_function?
In other words, you want to repeatedly call a function whether the user presses something or not?
1
2
3
while (true) {
  foo();
}


Thread. Have the eternal loop in separate thread. When the thread handling I/O finally receives something and that something is 5, then somehow signal the looper to quit.
I think he just wants the loop to exit as soon as the user inputs 5, and not get stuck on the cin>>t. However he could mean something else

Welp I guess not :D
Last edited on
^^exactly something i was thinking.. but just having a hard time finding a proper solution to solve this problem.. And how..
right now i am doing this

int j;
int t;
state = false;
If(!state)
{
do
{
j = custom_function(int)
   cout << "am i Done" << endl;
   cin >> t;
}
while(t!= 5);
state = true;
}
else
{
custom_function2(j); // just keeping looping this line. 
}
Last edited on
Topic archived. No new replies allowed.