环路初始化失踪 [英] for loop missing initialization

查看:110
本文介绍了环路初始化失踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过

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 to while (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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆