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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:24:50+00:00 2026-06-06T04:24:50+00:00

The contents of both of the following if blocks should be executed: if( booleanFunction()

  • 0

The contents of both of the following if blocks should be executed:

if( booleanFunction() || otherBooleanFunction() ) {...}
if( booleanFunction() | otherBooleanFunction() ) {...}

So what’s the difference between using | or using ||?

Note: I looked into this and found my own answer, which I included below. Please feel free to correct me or give your own view. There sure is room for improvement!

  • 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-06T04:24:52+00:00Added an answer on June 6, 2026 at 4:24 am

    The logical operator works on booleans, and the bitwise operator works on bits. In this case, the effect is going to be the same, but there are two differences:

    1. The bitwise operator is not meant for that, which makes it harder to read but most importantly
    2. The logical OR operator will evaluate the first condition. If it’s true, it does not matter what the next condition results in, the result will be true, so the second clause is not executed

    Here’s some handy code to prove this:

    public class OperatorTest {
    
        public static void main(String[] args){
            System.out.println("Logical Operator:");
            if(sayAndReturn(true, "first") || sayAndReturn(true, "second")){
                //doNothing
            }
    
            System.out.println("Bitwise Operator:");
            if(sayAndReturn(true, "first") | sayAndReturn(true, "second")){
                //doNothing
            }
        }
    
        public static boolean sayAndReturn(boolean ret, String msg){
            System.out.println(msg);
            return ret;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's the difference between console.log(process.cwd()) and console.log(__dirname); I've seen both used in similar contexts.
The contents of the following div is derived dynamically: i.e a table is added
I am loading contents into a same domain iframe. Does the html file that
For some reason I can't seem to get this particular web page's contents via
Take the following contents of a file: 52245 528 06156903 52246 530 00584709 What
I used the following code to display the contents of a Folder say images
Using JqueryMobile, I wish to achieve the following layout: Having nice decorations boxes to
The following code blends both DIVs together instead of displaying them vertically, one after
Given the following program: #include <iostream> #include <string> using namespace std; struct GenericType{ operator
I have a text file with the following contents repeating about 60 times coming

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.