while循环变量更新
请看这段代码:
int page;
int stop = FALSE;
while (!stop) {
printf("stop0 %i\n", stop);
if (physmem[fifo_index % opts.phys_pages] == NULL) {
stop = TRUE;
page = fifo_index % opts.phys_pages;
printf("stop1 %i\n", stop);
} else if (physmem[fifo_index % opts.phys_pages]->gc_bit == 0) {
physmem[fifo_index % opts.phys_pages]->gc_bit = 1;
printf("stop2 %i\n", stop);
} else if (physmem[fifo_index % opts.phys_pages]->gc_bit == 1) {
stop = TRUE;
page = fifo_index % opts.phys_pages;
printf("stop3 %i\n", stop);
}
printf("sto4 %i\n", stop);
fifo_index++;
printf("stop5 %i\n", stop);
}
输出是:
stop0 0
stop1 1
stop4 1
stop5 1
stop0 0 '<<< I dont understand this part'
stop1 1
stop4 1
stop5 1
'<<<< The code exits here!! In the second loop...whyy??'
Please look at this code:
int page;
int stop = FALSE;
while (!stop) {
printf("stop0 %i\n", stop);
if (physmem[fifo_index % opts.phys_pages] == NULL) {
stop = TRUE;
page = fifo_index % opts.phys_pages;
printf("stop1 %i\n", stop);
} else if (physmem[fifo_index % opts.phys_pages]->gc_bit == 0) {
physmem[fifo_index % opts.phys_pages]->gc_bit = 1;
printf("stop2 %i\n", stop);
} else if (physmem[fifo_index % opts.phys_pages]->gc_bit == 1) {
stop = TRUE;
page = fifo_index % opts.phys_pages;
printf("stop3 %i\n", stop);
}
printf("sto4 %i\n", stop);
fifo_index++;
printf("stop5 %i\n", stop);
}
The output is:
stop0 0
stop1 1
stop4 1
stop5 1
stop0 0 '<<< I dont understand this part'
stop1 1
stop4 1
stop5 1
'<<<< The code exits here!! In the second loop...whyy??'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 while 语句上方放置一个 printf 并检查是否进入循环两次。
You can put a
printf
abovewhile
statement and check if you are entering the loop twice.