Decrementing a loop counter as loop is executing

后端 未结 1 1439
不知归路
不知归路 2021-01-19 07:13

I\'m trying to decrement the counter of a for loop as the loop is running. Unfortunately, Lua doesn\'t seem to allow that. This piece of code should run forever:

<         


        
相关标签:
1条回答
  • 2021-01-19 07:55

    It's by design. From Lua reference manual:

    3.3.5 – For Statement

    All three control expressions are evaluated only once, before the loop starts. They must all result in numbers.

    So modifying the value of i inside the loop won't change how the loop runs.

    0 讨论(0)
提交回复
热议问题