Decrementing/Incrementing loop variable inside for loop. Is this code smell?

Posted by FairDune on Programmers See other posts from Programmers or by FairDune
Published on 2012-12-18T02:40:52Z Indexed on 2012/12/18 5:13 UTC
Read the original article Hit count: 121

Filed under:
|

I have to read lines from a text file in sequential order. The file is a custom text format that contains sections. If some sections are out of order, I would like to look for the starting of the next valid section and continue processing.

Currently, I have some code that looks like this:

for (int currentLineIndex=0; currentLineIndex < lines.Count; currentLineIndex++ )
{
    //Process section here
    if( out_of_order_condition )
    {
        currentLineIndex--;//Stay on the same line in the next iteration because this line may be the start of a valid section.
       continue;
    }
}

Is this code smell?

© Programmers or respective owner

Related posts about c#

Related posts about loops