What's the best way to do a backwards loop in C/C#/C++?

后端 未结 14 2668
终归单人心
终归单人心 2020-11-28 01:39

I need to move backwards through an array, so I have code like this:

for (int i = myArray.Length - 1; i >= 0; i--)
{
    // Do something
    myArray[i] =          


        
14条回答
  •  隐瞒了意图╮
    2020-11-28 01:59

    I would always prefer clear code against 'typographically pleasing' code. Thus, I would always use :

    for (int i = myArray.Length - 1; i >= 0; i--)  
    {  
        // Do something ...  
    }    
    

    You can consider it as the standard way to loop backwards.
    Just my two cents...

提交回复
热议问题