Dav*_*man 5 c for-loop boolean break while-loop
我在C,而不是C++中这样做.无论如何,如果我在for循环中放入一个break语句,它会仅停止for循环还是同时停止for和while循环?例如,这是我的代码中包含while和for的部分.我正在做的是让用户输入24小时的时间,我正在检查这个循环中的分钟(希望这是正确的).我关心的是,如果break语句只结束for循环,或者它将同时结束for和while,因为我只希望for循环结束.
boolean check = false;
while (!check){
int i;
for (i = 1; i < 24; i++)
{
int hour = i*100;
/* if the time has less hours than the hour counter*/
if ((hour - timeOfDay) < 100)
{
/*declare an illegal time when the number of minutes remaining*/
/*is greater than 59*/
if ((hour - timeOfDay) > 59)
{
check = false;
break;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10423 次 |
| 最近记录: |