For-Next Loop Optimization

The standard syntax for For-Next loops is to repeat the loop counter variable after Next (i.e. Next i). Placing the loop counter variable after Next is not required and unnecessarily slows down your macro. Omit the loop counter variable after Next to boost performance.

Standard For-Next Syntax

For i = iStart To iEnd
        ' Standard For-Next loop syntax has loop counter
        ' (i) after Next
Next i

Optimized For-Next Syntax

For i = iStart To iEnd
        ' Omit the loop counter variable after Next
  ' for better performance
Next

For i = iStart To iEnd
  ' Better yet…
        ' With nested and longer loops add the For statement
  ' as a comment after Next
Next 	' For i = iStart To iEnd
EnvisionCAD

EnvisionCAD

Since 1996, EnvisionCAD has been a nationally recognized leader in the configuration, customization, implementation, training & support for CAD software solutions. Our individualized approach has benefited private engineering firms and government agencies alike. Basic or advanced, we can help you get the most from your CAD technology.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *