Re: Cost/Benefit with respect to If ... Then.. structure

ScardyBob wrote:
I have a general question related to the structure of a If ... Then ...
statement. More specifically what are the costs/benefits from writing
an If ... Then ... statement as follows:

If i <> 0 Then
'Do Nothing
'Code you want to do something productive
End If

Rather then writing it as:

If i = 0 Then
'Code you want to do something productive
End If

I know this may seem like a stupid question, but I've been writing
certain If ... Then ... statements in the first manner, thinking they
are equivalent and simply a manner of personnel preference. Is there a
downside to this (besides having to write an extra line or two)?

The difference is the first one has an additional
instruction (the Else statement) that will consume a
nanosecond or two of execution time. This cost is modified
by the probablility of i being 0 or not. When i <> 0, there
is no difference, the additional execution time only occurs
when i = 0.

Bottom line, on today's modern computers, the difference is
so small that you will not notice it unless it is in a loop
with a very large number of iterations.

MVP [MS Access]