# How booleans work with if statements in Python?

**URL:** <https://forum.codewithmosh.com/t/how-booleans-work-with-if-statements-in-python/8575>\
**Category:** Python\
**Created:** [November 17, 2021, 12:25pm UTC](https://forum.codewithmosh.com/t/how-booleans-work-with-if-statements-in-python/8575 "2021-11-17T12:25:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![symen](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@symen](https://forum.codewithmosh.com/u/symen)\
**Post date:** [November 17, 2021, 12:25pm UTC](https://forum.codewithmosh.com/t/how-booleans-work-with-if-statements-in-python/8575/1 "2021-11-17T12:25:01Z")

</div>

hi Guys I just want to know how Booleans work with “if” statements because it has caused some confusing and I want to understand the logic behind it and I believe that many other beginners have the same confusing. here I have an example of a car game which runs perfectly fine but I want to understand how it works :

in the below code I want to understand why when I enter “start” the Else statement gets executed FIRST and when I enter “start” AGAIN and AGAIN the If statement keeps getting executed and not the Else statement

 ![py](https://us1.discourse-cdn.com/flex020/uploads/codewithmosh/original/2X/9/9c2aa1bdea3de536c50b56c98a41e59f07c0d44b.jpeg)

```auto
started = False
while True:
    word = input('enter : ')
    if word == 'start':
        if started:
            print('car already started')
        else :
            started = True
            print('car started')

```

---

<div class="post-metadata">

**Author:** ![some\_random\_coder](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@some\_random\_coder](https://forum.codewithmosh.com/u/some_random_coder)\
**Post date:** [November 17, 2021, 3:06pm UTC](https://forum.codewithmosh.com/t/how-booleans-work-with-if-statements-in-python/8575/2 "2021-11-17T15:06:47Z")

</div>

Whatever code inside `if` runs when the condition you passed to it resolves to True. Otherwise, the code inside `else` runs.

At the start of the loop, your `started` is always False. It only ever changes when it reaches the `else` block. After reaching the `else` block, it is always True. Because you never change it to something else.

That’s why when you initially start the car, you see “car started” message and afterwards you see “car already started” message.
