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 3600588
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:30:52+00:00 2026-05-18T20:30:52+00:00

I have always been taught to have one exit from functions and write code

  • 0

I have always been taught to have one exit from functions and write code that doesn’t jump all over the place, is the following bad code or is there a better way to write the for loop without needing an “exit for”?

dim dt as datatable = FillDataTableFunction()
dim bWrite as boolean = false
for each row as datarow in dt.rows
  if row.item("somecolumn") <> string.empty then 
    bWrite = true
    exit for
  end if 
next

if bWrite then 
  'do stuff
end if

I guess I am just thinking that this will reduce unneeded iterations through the for loop but for some reason it seems like a bad coding practice.

  • 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-05-18T20:30:52+00:00Added an answer on May 18, 2026 at 8:30 pm

    “I have always been taught” – at some point in life, people start learning rather than being taught 🙂

    Don’t take anything as gospel (even from me – if you disagree, make your own mind up). Look behind the guidelines to see why they exist.

    The reason why you were taught that multiple exit points is bad is because they often lead to code that is hard to follow. In other words, a 400-line function peppered with return statements is hard to analyse in terms of its behaviour.

    Your little code snippet does not suffer from this. The guideline I follow is: if you can see the control flow on a single screen in the editor, it’s fine. And, since 12 lines will fit in any editor I’ve used in the past two decades, your code is very readable.

    In fact, I’ve seen code from the “never use multiple exit points” people that is far less readable than that which would be produced by breaking their rules. It usually involves multi-condition while statements so convoluted that they have to break it across multiple lines, and is still a pain to analyse.

    Aim for readability. If guidelines help with that, use them. If not, throw them out the window.

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

Sidebar

Related Questions

I have always been for documenting code, but when it comes to AJAX +
I have always been a very big fan of the DHTML calendar http://www.dynarch.com/projects/calendar/ I
I have always been interested in algorithms, sort, crypto, binary trees, data compression, memory
Something I have always been interested in out of curiosity, is there a tool
I have always thought that the .equals() method in java should be overridden to
I have always made a point of writing nice code comments for classes and
We have always had languages that were preferable to be used in a particular
I have always used || (two pipes) in OR expressions, both in C# and
I have always wondered how people update a previous line in a command line.
I have always wondered WHaT tHE HecK?!? is the difference between JScript and JavaScript.

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.