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

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

问题描述

我正在自定义我在互联网上找到的代码(它是 Adafruit 推文收据).我无法理解代码的很多部分,但最令我困惑的是括号内有两个分号的 for 循环

I'm 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

for(;;) 是什么意思?(这是一个 Arduino 程序,所以我猜它是用 C 编写的.

What does for(;;) mean? (It's an Arduino program so I guess it's in C).

推荐答案

for(;;) {
}

功能上的意思

 while (true) {
 }

它可能会根据循环体内的某些条件中断循环/从循环返回.

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

for(;;) 永远循环的原因是因为for 包含三个部分,每个部分都是可选的.第一部分初始化循环;第二个决定是否继续循环,第三个在每次迭代结束时做一些事情.它是完整形式,您通常会看到如下内容:

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++)

如果缺少第一个(初始化)或最后一个(迭代结束)部分,则不会在它们的位置执行任何操作.如果中间(测试)部分丢失,那么它的作用就好像 true 在那里一样.所以for(;;)for(;true;)'是一样的,也就是(如上图)和while(true).

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天全站免登陆