Performance Differences of Nested If Else Statements vs. ElseIf Statements
A coworker and I have differing opinions on If statements and their
performance. My view is that If...ElseIf statements should be used. His
view is that he doesn't believe in ElseIf, and writes everything with
nested If statements.
Let's assume that a case statement cannot be used in this situation. What
I am wondering is how efficiently code will be executed using nested
If..Else statements versus using If...ElseIf statements. I know that code
readability is a factor, but that shouldn't' affect performance.
Lets look at the following examples.
Using If Else:
If () then
'Do something'
Else
If () then
'Do something'
Else
If () then
'Do something'
Else
If () then
'Do something'
Else
'Do something else'
End If
End If
End If
End If
Using ElseIf:
If () then
'Do something'
ElseIf () then
'Do something'
ElseIf () then
'Do something'
ElseIf () then
'Do something'
Else
'Do something else'
End If
I know this is a small scale example, but lets say blocks like this are
used heavily throughout the application.
Are there any performance differences between the two code sections, or
would they perform almost identically once the application is compiled?
No comments:
Post a Comment