duanpo6079 2015-06-04 20:22
浏览 14
已采纳

对于循环的前和后语句为空

In Golang what does it means that the pre and post statements of a for loop are empty like in this example:

    sum := 1
    for ; sum < 10; {
        sum += sum
    }
    fmt.Println(sum)
  • 写回答

3条回答 默认 最新

  • douwei1174 2015-06-04 20:33
    关注

    Remember that a for loop is the same as a while loop. Your code can be rewritten in other languages as

    sum := 1
    while(sum < 10) {
        sum += sum
    }
    fmt.Println(sum)
    

    In a for loop, there are 3 parts.

    for(initial statement ; condition ; end statement usually iterate)

    This is equivalent to

    initial statement
    while(condition) {
        Stuff here
        End iteration statement
    }
    

    The reason your loop can be written withiut the pre and post statements is because you've specified them in other parts of the code.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页