[cpp]
#include <iostream>
#include <windows.h>
using namespace std;
int CountBreakWhile(int n, int MilliSecondsOnce)//總次數, 每次多少毫秒,可為0
{
static int count = 0;//static
if(n<0 || MilliSecondsOnce<0)
{
return 1;
}
if(count >= n)
{
count = 0;
return 1;//已到達超時時間
}
count++;
Sleep(MilliSecondsOnce);
return 0;//未達到超時時間
}
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)//總次數, 每次多少毫秒,可為0
{
static int count = 0;//static
if(n<0 || MilliSecondsOnce<0)
{
return 1;
}
if(count >= n)
{
count = 0;
return 1;//已到達超時時間
}
count++;
Sleep(MilliSecondsOnce);
return 0;//未達到超時時間
}
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;
}