一个for循环括号内两个分号 [英] Two semicolons inside a for-loop parentheses

查看:1214
本文介绍了一个for循环括号内两个分号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

林定制code,我发现在互联网上(它的鸣叫Adafruit的收据)。我无法理解code的许多地方,但最令人费解的是我的for循环的括号内两个分号

 布尔jsonParse(INT深度,字节则EndChar){
  INT C,I;
  布尔readName = TRUE;  为(;;){//< ---------
    而(isspace为(C = timedRead())); //扫描过去的空白
    如果(C&小于0)返回false; // 时间到
    如果(C ==则EndChar)返回true; // EOD    如果(C =='{'){//对象如下
      如果返回false(jsonParse(深度+ 1,})!);
      如果(深!)返回true; //文件结束
      在结果列表中的对象,如果(深度== resultsDepth){//结束

这是什么作为(;;)是什么意思? (这是一个Arduino程序,所以我想这是在C)


解决方案

 为(;;){
}

功能意味着

 ,而(真){
 }

这可能会打破基于循环体中的一些条件循环/从环回报。

之所以为(;;)循环永远是因为有三个部分,的每这是可选的。第一部分初始化回路;第二判定是否继续进行循环,并且第三做了在每次迭代的结尾。它是完整的形式,你通常会看到这样的内容:

 为(i = 0;我小于10;我++)

如果第一个(初始化)或最后(结束迭代)的部分缺失,没有什么是他们的地方完成。如果中间(测试)部分缺失,那么它的行为就好像真正都在那里它的位置。因此,为(;;)相同的(真),这(如上图所示)是一样的,而(真)

Im customising a code i found over the internet (it's the adafruit tweet receipt). I cannot understand many parts of the code but the most perplexing to me is the for-loop with two semicolons inside the parentheses

boolean jsonParse(int depth, byte endChar) {
  int c, i;
  boolean readName = true;

  for(;;) {  //<---------
    while(isspace(c = timedRead())); // Scan past whitespace
    if(c < 0) return false; // Timeout
    if(c == endChar) return true; // EOD

    if(c == '{') { // Object follows
      if(!jsonParse(depth + 1, '}')) return false;
      if(!depth) return true; // End of file
      if(depth == resultsDepth) { // End of object in results list

What does for(;;) mean? (It's an arduino program so i guess it's in C)

解决方案

for(;;) {
}

functionally means

 while (true) {
 }

It will probably break the loop/ return from loop based on some condition inside the loop body.

The reason that for(;;) loops forever is because for has three parts, each of which is optional. The first part initializes the loop; the second decides whether or not to continue the loop, and the third does something at the end of each iteration. It is full form, you would typically see something like this:

for(i = 0; i < 10; i++)

If the first (initialization) or last (end-of-iteration) parts are missing, nothing is done in their place. If the middle (test) part is missing, then it acts as though true were there in its place. So for(;;) is the same as for(;true;)', which (as shown above) is the same as while (true).

这篇关于一个for循环括号内两个分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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