Previous | Index | Next 

[HOWTO] Convert While loops into Do loops

Note: this article only applies to conversions to VB.NET.

You can transform While…Wend loops – which are leftovers from early Visual Basic versions – into more modern Do While loops using a PostProcess pragma. VB Migration Partner converts the Wend keyword into “End While”, therefore we must look for this latter keyword, and we also need to account for Exit While statements:

        '## PostProcess  "(?<=\n[ \t]*)End While\b", "Loop", True
        '## PostProcess  "\bExit[ \t+]While\b", "Exit Do", True
        '## PostProcess  "(?<=\n[ \t]*)While[ \t]+(?<cond>.+)", "Do While  ${cond}", True

Notice however that this transformation doesn’t really improve your code readability or execution speed; nevertheless it concurs to “modernize” the look of your code. Also, after the conversion into a Do…Loop block you can apply a couple of optimization, as explained in this article.

 

Previous | Index | Next