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

  • Home
  • SEARCH
  • 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 3272140
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:47:46+00:00 2026-05-17T18:47:46+00:00

Just one quick question, say, Car class extends HashMap(String, String). 1. for (Car car

  • 0

Just one quick question, say, Car class extends HashMap(String, String).

1.

for (Car car : carList) {
    if (car.isEmpty) {
        break;
    }
    doSomething();
}

2.

for (Car car : carList) {
    if (!car.isEmpty) {
        doSomethingElse();
    }
}

Which of the above two is better?
Thanks.

—- edited —-
Sorry I did not make my point clear.

The doSomething() method is actually doing different things.
I’ve changed them to doSomething() and doSometingElse().

My question is, will you put all the process in one if()? or first break the loop if the if() condition does not satisfy.

Thanks.

  • 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-17T18:47:46+00:00Added an answer on May 17, 2026 at 6:47 pm

    If you actually meant “continue” and not “break”, then I’d say not using continue or break is better.

    It’s not a huge deal, but statements like continue, break and return are all essentially goto statements that have been dressed up a little. Instead of goto a line or goto a label they goto the top or bottom of a control structure–it makes the programmer have to think a little bit when they track it which means wasted time and additional chances for errors.

    It’s not a terribly big deal, and many times these structures will actually clarify your code, but if you have a choice and they seem to do essentially the same thing, go the way that doesn’t involve sending control elsewhere.

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

Sidebar

Related Questions

this query will just one row as a result myDataContext db = new myDataContext();
I'm trying to highlight just one specific row in a table using jQuery. The
Handling multiple merges onto branches in Subversion or CVS is just one of those
The MFC application that i created is dialog based. Just one dialog thats all.
I have a web page with 3 forms on it. Not nested, just one
I've just started one of my courses, as classes just began 2 weeks ago,
I'm just a one-man software shop, and I currently have an MSDN subscription. It
Why does a System.Boolean take 4 bytes? It just stores one state, either true
Just flicking through one of my favourite books (Ellen Ullman's The Bug) and there
How do I fix a broken debugger, one that just won't start, in EclipseME

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.