Been looking at some example code and I'm seeing a lot of Exit Sub" used to prematurely exit a loop or if statements. Is there any issues with this or just bad practise?
I tend to avoid it (not sure why), but finding it easier with more complex loops and if statements.
Example
vs
Assuming both set of sub's have no additional commands.
vs
The only reason I would use the exit sub in the "IF" scenario is so I don't have 20 more commands indented and nested within the if statement. As when I have complex if-else or case statements, I can exit sub each time when I know I've hit all the validations I need.
I tend to avoid it (not sure why), but finding it easier with more complex loops and if statements.
Example
Code:
found =false
do until found or eof
if recordfound then
found = true
else
nextrecord
loop
Code:
do until eof
if recordfound then
exitsub
else
next record
loop
Code:
if eof then
do some stuff
else
next record
do 20 more commands
end if
Code:
if eof then
do some stuff
exit sub
end if
next record
do 20 more commands