The World of Conditional Statements

Conditional Statements

Conditional Statements are statements that set a condition for the code. An example is: if i==True:. That is a statement that sets a condition. So if i==True is True, then it would run the code in the if body. If the statement is false, it would just skip the if body and move on with the code. Before we get too much into if statements, let's look at the basics.

If statement flowchart

I play golf every day. But, when it’s raining I won’t play golf. So, we can set a condition.

Here I am setting a condition if it’s raining. If the statement is true, it will print ‘It is raining’. If it’s false, it will print nothing.

As you can see, we can use conditional statements in our everyday life.

The if statement is not the only statement that can set a condition. The elif and else also can set conditions. Let’s talk about elif statements. If the if statement is false, you can add an elif statement to set another condition for your code. You can add multiple elif statements.

Elif Statement Flowchart

Now let’s talk about the else statement. If all the statements you add are false, you can use the else statement. The else statement doesn’t specify a condition. It just says ‘Hey, if all you guys are false I will execute my else body.’

If, elif, and else flowchart

That is all about conditional statements.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Bending Moment and Shear Force Diagrams for Solid Bodies in ANSYS Workbench | Nick J Stevens

Data Engineer Blog 0x0001 (2021–09–30)

Understanding Guilded — Flow Bots

Gradle & Gradle : All about Gradle

Lazy World on PC — How to get started

Integrating Mi Home sensors to ThingsPH IoT Platform using Raspberry Pi

How to be a software developer within a year.

The MechArcade Reveal Mechanism

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Golf Teachers

Golf Teachers

More from Medium

Change is possible!

Who exactly are you?

Is it Time to Rethink Insurance? The Tip Jar Analogy

What if I could tell you death was just the beginning?