环路初始化失踪 [英] for loop missing initialization
问题描述
我见过
for(;;)
和
for ( ; *s != '\0'; s++)
为什么空白这样。谢谢你。
Why is it blank like that. Thanks.
推荐答案
的为
语句的工作方式:
为(初始化;试验条件;更新)
和任何或所有这三个的可省略(左空白)。所以:
And any or all of those three can be omitted (left blank). So:
-
为(;;)
是一个无限循环 1 等同于,而(真)
因为没有测试条件。事实上,的for(int i = 0;我+ +)。
也将是一个无限循环 1
for (;;)
is an infinite loop1 equivalent towhile (true)
because there is no test condition. In fact,for (int i=0; ;i++)
would also be an infinite loop1.
为(;!* S ='\\ 0'; S ++)
是一个没有初始化一个循环。 取值
将指向(可能)的字符串开始,便会增加,直至达到空字符'\\ 0'
表示结束的字符串。这主要是通过字符串取值
for ( ; *s != '\0'; s++)
is a loop with no initialization. s
will point to the beginning of (probably) a string and is incremented until it reaches the null character '\0'
denoting end-of-string. This essentially means loop through all characters of the string s
1 ,如果有一个破
语句中的循环体,或呼叫仍将对循环被中断退出()
,等...
1 The loop will still be interrupted if there's a break
statement in the loop body, or a call to exit()
, etc...
这篇关于环路初始化失踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!