Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8221653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:00:10+00:00 2026-06-07T14:00:10+00:00

Recently I’ve been working on legacy vb.net code and during code peer review it

  • 0

Recently I’ve been working on legacy vb.net code and during code peer review it was recommended not to use Exit Sub / Function but instead to nest all functionality in IF statements.

When I initially started developing I used to do it this way instinctively (Nest the IF’s), not only did it seem more logical, it just seemed less confusing.

However at some point I worked with a team that treated nested IF’s as “evil”, and so Exit subs / functions I was told was preferred. I’m pretty sure they produced some MS best practice material to back this up.

So this question is for experienced developers, which way is truly preferred? If you give an answer could you also please state your sources, or just mention that this is a preference preferred by your team / company / personal and give reasons.

Thanks in advance.

EDIT as requested: Code Samples

Exit Sub :

Private Sub DoSomeWork()
 if not conditionMetFromAnotherFunction() then
      exit Sub 
 end if

 'Method work starts here
End Sub

Nested IFs:

Private Sub DoSomeWork()
 if conditionMetFromAnotherFunction() then
     'Method work starts here
 end if
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:00:15+00:00Added an answer on June 7, 2026 at 2:00 pm

    As David pointed out in his comment, nested if statements can add to the complexity of your code.

    Imagine the following (simplified) code :

    Private Sub DoSomeWork()
        if conditionMetFromAnotherFunction() then
            if conditionDependantUponPreviousCondition then
                ' Do the work
            end if
        end if
    End Sub
    

    Or the following

    Private Sub DoSomeWork()
        if not conditionMetFromAnotherFunction()
            return
        else if not conditionDependantUponPreviousCondition 
            return
        end if
    
    
        ' If we're here, everything's all good
        ' Do the work...
    End Sub
    

    If your conditions get more complex, returning makes it much more easy to understand that under some conditions, your code is not doing anything, and makes your code more readable.

    Otherwise, you have to read all the function and mentally parse the nested if’s to see that nothing’s done.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I've been doing quite the project mostly working with the DateTime class. Now,..
Recently I've been experimenting with the use of the Func<T> class, and so far
Recently I have been investigating the possibilities of caching in ASP.NET. I rolled my
Recently, I've been dealing with an error with accessing MAPI via the .NET framework
Recently I was working with some JavaScript code and I found this: <script type=text/javascript>
Recently I was asked to develop an app, which basically is going to use
recently, while working on a db2 -> oracle migration project, we came across this
Recently I've noticed that on occasion I do not get a mayorship notification when
Recently I have been dealing with windows LogonUser API. The LogonUser api returns different
Recently I've begun to code in Objective-C for iOS 5 devices. My brand new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.