Now I have a sub to validate a bunch of textboxes and combo boxes.
I previously used many IF statements to validate and pop up different messageboxes and Exit Sub in every IF statement.
But I heard that too many Exits will decrease the efficiency and they were not recommended to use. Instead, nested IF is better because it will let the process naturally go to the end.
Then I found out that if I use nested IF, it will be hard to read, since messageboxes are all separated from conditions.
I have no software development experience. So my question is: in the real projects, which style will you choose?
You should use what is more readable and what you agree with your team.
As for having many
Exitsdecreasing performance – I don’t know if that is true, but even if it was, I would expect it to be such a minimal amount to me a micro-micro-optimization. This is something you can easily test yourself – run both types of code in a loop (millions/billions of times) and measure how much time each took using theStopWatchclass.I personally find multiple returns easier to read in this specific case and it is my usual style.