for loop without index declaration

前端 未结 5 1344
误落风尘
误落风尘 2021-01-24 00:11

So I declare a variable some where and initialize it. Now later on I need to use it to loop while its still positive so I need to decrement it. To me looping using a condition a

5条回答
  •  情歌与酒
    2021-01-24 00:55

    Use a while loop?

    while (space > 0) { /* code */ space--; }
    

    If you don't need the value of space in the body of the loop:

    while (space-- > 0) { /* code */ }
    

提交回复
热议问题