The World of Conditional Statements

Golf Teachers
2 min readMar 24, 2021

--

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.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Responses (1)

Write a response