What's the rule of thumb for nested if-endifs

L

Lars Brownie

I often stumble across the question of wether it's better to write:

if then
exit sub
endif
etc.

or to nest all my if-endifs in one big if endif.

if then
if then
if then
endif
endif
endif

I once heared that the latter is the 'standard' but often I find it harder
to read.
Is there perhaps a rule of thumb for this?
Thanks, Lars
 
A

akphidelt

I guess it depends, Ill use the nested if's, if what happens after that
doesn't matter. But if a criteria is met where I want to stop code execution
I'll use the Exit Sub. Otherwise if you want the code to run regardless of
the if statements then there is no reason to use exit sub.
 
B

BruceM

Without specifics it's hard to say, but I wonder if ElseIf would help. As
was mentioned in the other response, it depends on what you need to do.
There are several options, depending on the circumstances. Select Case, to
name one example, is another way of handling multiple conditions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top