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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:17:05+00:00 2026-05-29T06:17:05+00:00

I’ve done some reading of previous posts and I’ve learned some things but want

  • 0

I’ve done some reading of previous posts and I’ve learned some things but want to verify how some loops are working. In reading, am I right in understanding that “true” has higher precedence than “false”? For instance:

/.../
return (true || false);

will return “true” (regardless of order)?

If I have a boolean recursive function that calls 3 variations of itself…all I need is for one version to return true for the whole funct to return true, correct? The function below creates it’s stack frame, then the return call creates 3 more stack frames and runs through the calls, then if one returns true the whole funct returns true because true has precedence over false… Is this assumption correct?

Ie:

/* This function is taking a given weight and seeing if it can be offset by available 
 * weights. Depending on what weights are available, the weights can be directly opposed
 * to "weight" (opposite side of scale) or added to... The recursive calls will either all 
 * return false, all return true, or a variation thereof.  All that I can is that if one 
 * branch returns true, the overall function returns true...
*/

bool CanMeasure(int weight, std::vector<int> &availableWeights, int index = 0)
{
    /.../
    // the below can return all true, all false, or some variation thereof...
    return (CanMeasure(weight + availableWeights[index], availableWeights, index + 1) ||
            CanMeasure(weight - availableWeights[index], availableWeights, index + 1) ||
            CanMeasure(weight, availableWeights, index + 1));
}

Thanks guys!

  • 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-29T06:17:06+00:00Added an answer on May 29, 2026 at 6:17 am

    Yes (it will return true regardless of order). The conditions in the or are evaluated from left to right, and when the first true is stumbled upon, the whole condition returns true.

    In your example:

    return (CanMeasure(weight + availableWeights[index], availableWeights, index + 1) ||
            CanMeasure(weight - availableWeights[index], availableWeights, index + 1) ||
            CanMeasure(weight, availableWeights, index + 1));
    

    not all conditions are necesarily evaluated. If the first one evaluates to true, the others will not execute, and the function will just return true.

    It’s called short-circuiting.

    Let’s take a look at some dissasembled code:

       if ( foo() || goo() )
    0041152E  call        foo (41111Dh) 
    00411533  movzx       eax,al 
    00411536  test        eax,eax 
    00411538  jne         wmain+36h (411546h) 
    0041153A  call        goo (4111A9h) 
    0041153F  movzx       eax,al 
    00411542  test        eax,eax 
    00411544  je          wmain+49h (411559h) 
    

    In this example, foo() and goo() are both functions returning bool.

    The instruction

    00411538  jne         wmain+36h (411546h) 
    

    tells the runtime to jump out of the conditional if foo() evaluated to true.

    This code is not optimized, so it’s not an optimization feature.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported

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.