while循环变量更新

发布于 2024-11-02 01:58:50 字数 943 浏览 5 评论 0原文

请看这段代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我不会写诗 2024-11-09 01:58:50

您可以在 while 语句上方放置一个 printf 并检查是否进入循环两次。

You can put a printf above while statement and check if you are entering the loop twice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文