[Cpp]
# Include <iostream>
# Include <windows. h>
Using namespace std;
Int CountBreakWhile (int n, int MilliSecondsOnce) // The total number of times, each time in milliseconds, can be 0
{
Static int count = 0; // static
If (n <0 | MilliSecondsOnce <0)
{
Return 1;
}
If (count> = n)
{
Count = 0;
Return 1; // Timeout reached
}
Count ++;
Sleep (MilliSecondsOnce );
Return 0; // timeout not reached
}
Int main (int argc, char * argv [])
{
While (1)
{
If (CountBreakWhile (3,100 ))
Break;
Cout <"hello" <endl;
}
While (1)
{
If (CountBreakWhile (5, 0 ))
Break;
Cout <"world" <endl;
}
Return 0;
}
# Include <iostream>
# Include <windows. h>
Using namespace std;
Int CountBreakWhile (int n, int MilliSecondsOnce) // The total number of times, each time in milliseconds, can be 0
{
Static int count = 0; // static
If (n <0 | MilliSecondsOnce <0)
{
Return 1;
}
If (count> = n)
{
Count = 0;
Return 1; // Timeout reached
}
Count ++;
Sleep (MilliSecondsOnce );
Return 0; // timeout not reached
}
Int main (int argc, char * argv [])
{
While (1)
{
If (CountBreakWhile (3,100 ))
Break;
Cout <"hello" <endl;
}
While (1)
{
If (CountBreakWhile (5, 0 ))
Break;
Cout <"world" <endl;
}
Return 0;
}