for loop without index declaration

前端 未结 5 1434
误落风尘
误落风尘 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 01:01

    The latter way is reasonable. An alternative - if you don't have any break/continue statements - would be:

    while (space > 0)
    {
        // Code
    
        space--;
    }
    

提交回复
热议问题