#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;
}


相关文章:

  • 2022-12-23
  • 2021-04-22
  • 2021-10-12
  • 2022-12-23
  • 2021-08-02
  • 2021-11-25
  • 2021-08-10
  • 2021-04-22
猜你喜欢
  • 2021-07-26
  • 2022-02-09
  • 2021-07-05
  • 2021-06-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案