# Conditional Statement

> An if runs code only when a test is true. Else runs when it is not.

**Field:** Software Development  
**Category:** Programming Concepts  
**Also known as:** If Statement, If Else, Conditional

## Think of it like

Think of it like a fork in a path. If it rains you take the left path, else you take the right.

## Definition

A conditional statement runs some code only when a test is true. It starts with if, followed by a question like temp > 25. If the answer is true, the lines inside run. An else part can say what to do when the answer is false. Many languages add elif or else if to check more than one test in turn.

## Example

A weather app checks if temp > 25. On a 30 degree day in Madrid it says shorts; on a cold day it says bring a coat.

## Example code

```python
temp = 30
if temp > 25:
    print("Shorts today")
else:
    print("Bring a coat")
# prints: Shorts today
```

The test is true, so only the first message is shown.

## Why it matters

Ifs are how a program makes choices. Every rule like you must be 13 to join is an if.

## Common mistake

Putting the tests of an elif chain in the wrong order. The first true test wins, and the rest are skipped.

## Three principles

- **Test first.** The code inside runs only on true.
- **Else catches the rest.** It runs when the test is false.
- **First match wins.** In a chain, later tests are skipped.

## Related terms

- [Boolean](https://learn.benibix.com/term/development/boolean)
- [Comparison Operator](https://learn.benibix.com/term/development/comparison-operator)
- [Control Flow](https://learn.benibix.com/term/development/control-flow)
- [Logical Operator](https://learn.benibix.com/term/development/logical-operator)
- [Switch Statement](https://learn.benibix.com/term/development/switch-statement)

## Taught in

- [If, Else and Match](https://learn.benibix.com/learn/development-concepts/if-else-and-match): Programming Basics, 10/18

---

Source: https://learn.benibix.com/term/development/conditional-statement
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
