Jump to content

if (confusin)


Recommended Posts

That's exactly the kind of place to use an else if. It makes program execution more efficient and also reminds you, the developer, that you only want to execute one code block, not several. That makes it easy to remember what you want to happen.

if (h == 1){   // execute this}else if (h == 2){   // execute that}

Not using an else might imply to you, the developer, that a set of conditions could exist where both code blocks could be executed. This way, it's absolutely clear that that will never happen.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...