【问题标题】:Simulating the "continue" directive, and other alternatives模拟“继续”指令和其他替代方案
【发布时间】:2017-03-29 03:34:22
【问题描述】:

一些编程语言支持循环中的“继续”指令以跳到下一个循环。您如何在没有此指令的语言中实现相同的目标?我现在在 povray 中面临需要这种行为的情况。谢谢。

【问题讨论】:

    标签: loops continue povray


    【解决方案1】:

    在最简单的情况下,只需使用条件:

    #for (i, from, to)
      // do common actions
      #if (<condition is true>)
        // do something special to the condition
      #end
    #end
    

    或者,您可以使用 POV-Ray 3.7 supports the #break statement 来模拟 continue,但需要一点递归的帮助 - 但是,这非常笨拙和不优雅:

    #macro LoopWithContinuation(from, to)
      #for (i, from, to)
        #if (<condition is true>)
          LoopWithContinuation(i + 1, to)
          #break
        #else
          // do something
        #end
        #debug ""
      #end
    #end
    
    LoopWithContinuation(1, 20)
    

    但请记住,POV-Ray 的递归深度限制为 200,因此这种方法不适合较长的循环。

    【讨论】:

      猜你喜欢
      • 2014-10-22
      • 2014-07-08
      • 2011-07-24
      • 1970-01-01
      • 2019-10-19
      • 1970-01-01
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      相关资源
      最近更新 更多