gpt4 book ai didi

在 do while 循环中的 continue 语句

转载 作者:行者123 更新时间:2023-12-04 14:33:57 27 4
gpt4 key购买 nike

#include <stdlib.h>
#include <stdio.h>
enum {false, true};

int main()
{
int i = 1;
do
{
printf("%d\n", i);
i++;
if (i < 15)
continue;
} while (false);

getchar();
return 0;
}
continue 之后会发生什么在这段代码中执行语句?
控制去哪儿了?

最佳答案

下一条语句将是 while (false);结束 do-while循环后执行 getchar();一般来说:

do
{
...
statements
...

continue; // Act as "GOTO continue_label"

...
statements
...

continue_label:
} while (...);
如果您想尝试一下,可以使用以下代码:
int i = 0;
do
{
printf("After do\n");
++i;
if (i < 2)
{
printf("Before continue\n");
continue;
}
printf("Before while\n");
} while(printf("Inside while\n") && i < 2);
输出+注释来解释:
After do              // Start first loop
Before continue // Execute continue, consequently "Before while" is not printed
Inside while // Execute while
After do // Start second loop
Before while // Just before the while (i.e. continue not called in this loop)
Inside while // Execute while

关于在 do while 循环中的 continue 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64120214/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com