Discover This #1 Secret About The ‘If’ Statement In Coding… And Improve YOUR Coding Skills Immediately!

From The Desk Of: Michiel Arkema

Re: The #1 secret about ‘If’ statements in coding that everyone should know… NOW!

Hey There Fellow Coders,

So as a software developer, you most likely are quite familiar with the all-famous ‘If’ statement.

But are you exactly aware of how it works in the background? Well, no matter the answer that you just gave, let’s keep reading.

So just to make everything as obvious as possible, let’s take a look at what a simple if statement looks like. And for the following examples, let’s use the Python programming language.

This is a image that shows a Simple If statement example in Python
Simple If statement in Python.

Now let’s digest what is happening in the code above.

  1. We created a simple Boolean variable
  2. We check if the value is True, and if so, it will print out a very happy message ๐Ÿ™‚

But would would happen if the value would be False instead?

Well it’s simple, nothing would happen. Why? Well because our if statement is only executed when the value is True.

Now, let’s do something fun, let’s negate the if statement but putting the ‘not’ keyword in front of it. (Don’t make fun of my drawing skills oke?)

Image showing the if statement with not keyword.

Now, Let’s see what would happen if we were to execute the code.

The Result will look like this:

So now you are probably thinking, why do we get a result when our value is set to False?

Well the answer is simple, by using the ‘not’ keyword in front of condition. We checked if the value is False, and because it is indeed False, the check returns True.

Get it? If not, let’s take a look if we would execute the same condition and print out its value.

The code to check the condition.

As you can see up here, the condition returned true. Why? well its simple, we checked if the variable was not True, and we did so by putting the ‘not’ keyword in front of it.

So What Is The Big Magic Secret Then?

Well, the secret is simple but still many don’t know it. An ‘If’ Statement only executes if the condition is True. If it’s False, the statement will be skipped.

So hopefully you discovered something new from this post and if you did, I recently started a public FaceBook group where I will be sharing 8 years of experience in programming with you. Sounds cool? Then join NOW!
Click on this link: https://www.facebook.com/groups/confidentcoderscommunity


Your Friend And Coaching Buddy: Michiel (Coding Dude) Arkema

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.