break while(1)

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


posted @ 2013-03-28 21:19  xinyuyuanm  阅读(182)  评论(0编辑  收藏  举报