---
epic: 6
story: 6.6
title: "Conditionals"
status: draft
---

## Epic 6 — Advanced Math & Functions
**Goal:** Scientific, financial, and power-user math.

### Story 6.6: Conditionals

As a **CalcPad user**,
I want to write conditional expressions using `if/then/else`,
So that I can model decision logic such as tax brackets and tiered pricing directly in my calculations.

**Acceptance Criteria:**

**Given** a variable `revenue = 150000`
**When** the user writes `if revenue > 100k then revenue * 0.15 else revenue * 0.10`
**Then** the result is `22500` (the `then` branch is taken because 150000 > 100000)

**Given** a variable `revenue = 80000`
**When** the user writes `if revenue > 100k then revenue * 0.15 else revenue * 0.10`
**Then** the result is `8000` (the `else` branch is taken because 80000 is not > 100000)

**Given** the user writes `if 5 > 3 then 10 else 20`
**When** the engine evaluates
**Then** the result is `10`

**Given** the user writes `if 2 > 3 then 10 else 20`
**When** the engine evaluates
**Then** the result is `20`

**Given** the user writes `if x > 10 then x * 2 else x` where `x` is undefined
**When** the engine evaluates
**Then** an error is displayed indicating that `x` is not defined

**Given** the user writes a conditional comparing values with units, e.g., `if distance > 100 km then 50 else 30`
**When** the engine evaluates with `distance = 150 km`
**Then** the result is `50` (the comparison respects unit context)

**Given** the user writes a conditional without an `else` clause, e.g., `if revenue > 100k then revenue * 0.15`
**When** the engine evaluates with `revenue = 80000`
**Then** the result is `0` or `null`/blank (a sensible default when the condition is false and no else is provided)

**Given** the user writes a nested conditional: `if a > 10 then if a > 20 then 3 else 2 else 1`
**When** the engine evaluates with `a = 25`
**Then** the result is `3`
