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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:53:57+00:00 2026-05-22T18:53:57+00:00

I was coding away today when I came across something I do all the

  • 0

I was coding away today when I came across something I do all the time without thinking as wondered if it had any after affects.

Here are two ways of doing the same thing

if(foo != true)
{
bar ++;
}

if(foo == true)
{
}
else
{
bar ++;
}

Now I know the compiler would probably optimise this to the same thing but I want to know the difference because you cannot always count on them.

My question is really would the second option incur some kind of penalty because it adds another command to the check ?

Yes it was a typo.

  • 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-22T18:53:58+00:00Added an answer on May 22, 2026 at 6:53 pm

    Neither is good. Apart from the fact that the second contains a typo (= instead of ==), comparing booleans to constants is just redundant. Just test their values directly:

    if (! foo) …
    // Instead of
    if (foo != true) …
    
    // or
    
    if (foo) …
    // Instead of
    if (foo == true) …
    

    First of all, it removes the possibility of creating bugs though typos (as you have graciously shown). But apart from that it’s just more logical.

    (Note however that it’s not more efficient. The statements are strictly equivalent.)

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

Sidebar

Related Questions

Mine is this: Hard coding is the way! All my problems go away. Just
Here's the situation: I'll be coding away in VS 2010, when all of a
Today I was happily coding away when I got to a piece of code
I've been coding a webapp for some time now and all the layout, css
Coding i came around to check for the vararg performance of Java. I write
I'm coding a tab system for my website that must be entirely CSS/HTML/JS (without
I'm trying to move away from hard coding things like text boxes. I'm using
I am coding in GWT 2.3 using Eclipse. While I have had coding experience,
Coding in Delphi, attaching an OnKeyPress event handler to a TStringGrid: The OnKeyPress event
Coding footer naively, if there's not enough content, then there will be empty space

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.