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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:44:59+00:00 2026-06-04T03:44:59+00:00

Below are two snippets. Notice the ONE AND ONLY difference between the programs is

  • 0

Below are two snippets. Notice the ONE AND ONLY difference between the programs is that one break to return and the other return immediately. I understand it’s good design practice to have one point of exit inside a method. But I am not worrying about design here. If I pay extra for using break, how much extra computation/memory/clock-cycle do I pay?

Program one:

public boolean doThis(String[] A){
  boolean indicator = false;
  for(int i=0; i<A.length; i++){
      if(A[i].equals("Taboo"))
        break;
      for(int x=0; x<=i; x++)
          //some work is done here. to make indicator true or false
  }
  return indicator;
}

Program two:

public boolean doThis(String[] A){
  boolean indicator = false;
  for(int i=0; i<A.length; i++){
      if(A[i].equals("Taboo"))
        return false;
      for(int x=0; x<=i; x++)
          //some work is done here. to make indicator true or false
  }
  return indicator;
}
  • 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-04T03:45:00+00:00Added an answer on June 4, 2026 at 3:45 am

    If your compiler is any good, you pay a tiny bit less for the “return false” case.

    You might be thinking that the “break” is expensive. With a crummy compiler, it is a single jump instruction that lands on the return. A good compiler will realize the jump is superflous, and can lift the return statement to the point of the break, if you don’t mind expanding the code.

    What makes the “return false” case slightly cheaper, is that “return indicator” may require a fetch from a memory to place the result in the calling-convention result-return register almost universally used by compilers. “return false” loads the constant into a register (in particular, the result-return register); this is always faster than fetch-from-memory on modern machines because the literal is embedded in the instruction stream, which the processor has already fetched.

    A sophisticated compiler might keep all the variables in registers. In this case, “return indicator” may actually be faster, because a smart compiler may have schemed to place “indicator” in the result-return register; no work required to load the value. For the program you coded with a call on string equal, I doubt the compiler will try to keep all the variables in the registers; it would just have to expensively spill them all on the call to equal.

    All this fine detail aside, this isn’t the kind of thing you should worry about optimizing.

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

Sidebar

Related Questions

I need a function that can return the difference between the below two dates
Is there any difference between the below two snippets? One is a char array,
Below are two programs that are almost identical except that I switched the i
i have to display two images one below the other. The images should look
Though the two snippets below have a slight difference in the manipulation of the
The two programs below get n integers from file and calculates the sum of
Why the two query below return duplicate member_id and not the third? I need
Consider the two following regular expression snippets and dummy HTML that it should be
See my code snippet below: var list = ['one', 'two', 'three', 'four']; var str
I'm a jQuery newbie. Here are two code snippets that move the h1 element

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.