【发布时间】:2016-02-28 02:43:29
【问题描述】:
我有一个 while 循环,当满足某些条件时退出。即,
boolean end = false;
while(!end){
//Some operations based on random values
//if statement to check my condition, and if it is met, then
end = true; //exits loop
}
现在,由于我的程序是根据生成的随机数执行的,因此有时循环运行 > 1000 次,有时运行
【问题讨论】:
-
在循环外取一个计数变量并在循环内递增并检查此计数变量。当这个变量达到 1000 时就破掉它。