关于无限循环,有约 $ \infty $ 种写法,从难度上分,可分为三类:
第一种: 用while |
第二种: 用for |
第三种: 用goto |
|
---|---|---|---|
C/C++ |
while(1) while(true) |
for(;;) for(;1;) for(;true;) |
x: ... goto x; |
Python |
while 1 while True |
\ | \ |
具体示例:
Python - while
:
while 1:
print(end = '.')
while True:
print(end = '.')
C/C++
:
// while
while(1)
{
printf(".");
}
while(true)
{
printf(".");
}
// for
for(;;)
{
printf(".");
}
for(;1;)
{
printf(".");
}
for(;true;)
{
printf(".");
}
// goto
again:
printf(".");
goto again;