Simplifying Control Flow

Flatten nested conditionals with early returns or table-driven methods - keep nesting depth under 3 levels

43 stars 26 forksSoftware Development

Install

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add obra/clank --skill Simplifying Control Flow
Manual install
git clone --depth 1 https://github.com/obra/clank.git /tmp/clank
mkdir -p ~/.claude/skills
cp -r /tmp/clank/skills/coding/simplifying-control-flow ~/.claude/skills/Simplifying-Control-Flow

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# Simplifying Control Flow

## Overview

Nested conditionals are hard to understand and error-prone. Flatten them.

**Core principle:** Nesting depth < 3 levels. Use early returns, table-driven methods, or extracted conditions.

## Baseline Violation

**Agents create nested if/else for multi-condition logic:**

❌ **Nested (baseline):**
```python
def calculate_discount(order_amount, is_vip):
    if is_vip:
        if order_amount > 1000:
            return 0.20
        elif order_amount > 500:
            return 0.15
    else:
        if order_amount > 1000:
            return 0.10
        elif order_amount > 500:
            return 0.05
    return 0.0
```

**Problems:** Duplicated logic, hard to see all tiers, adding tier requires finding nesting spot.

## Three Techniques

### 1. Flatten with Combined Conditions

✅ **All at same level:**
```python
def calculate_discount(order_amount, is_vip):
    if is_vip and order_amount > 1000: return 0.20
    if is_vip and order_amount > 500: return 0.15
    if order_amount > 1000: return 0.10
    if order_amount > 500: return 0.05
    return 0.0
```

### 2. Table-Driven (Best for Data)

✅ **Business rules as data:**
Read the full skill on GitHub

Details

Skill name
Simplifying Control Flow
Repository
obra/clank
Path
skills/coding/simplifying-control-flow/SKILL.md
Repo updated
9 October 2025

FAQ

What does the Simplifying Control Flow skill do?

Flatten nested conditionals with early returns or table-driven methods - keep nesting depth under 3 levels

How do I install the Simplifying Control Flow skill?

skills CLI (Claude Code, Cursor, Codex and more): npx skills add obra/clank --skill Simplifying Control Flow. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Simplifying Control Flow popular?

It lives in obra/clank, which has 43 GitHub stars and 26 forks.

Related skills

Gardening Skills Wiki

43

obra/clank

Maintain skills wiki health - check links, naming, cross-references, and coverage

Other26

Remembering Conversations

43

obra/clank

Search previous Claude Code conversations for facts, patterns, decisions, and context using semantic or text search

AI, LLMs & Agents26

Brainstorming Ideas Into Designs

43

obra/clank

Interactive idea refinement using Socratic method to develop fully-formed designs

Software Development26

Single Purpose Variables

43

obra/clank

Use each variable for exactly one purpose - no hybrid coupling or hidden meanings

Software Development26

Sams Architecture

38

sam-dumont/claude-skills

Automatically triggered when designing system architecture, planning new projects, creating implementation plans, conducting architecture reviews, or auditing existing codebases for consistency. Applies when discussing: system design, technology choices, architectural patterns, infrastructure decisions, API design, testing strategies, CI/CD pipelines, security architecture, or code organization. Works for Python web APIs, infrastructure/DevOps, Garmin/embedded systems, and frontend projects. Distinguishes between personal projects (strict standards) and client work (adaptive approach).

Software Development

Stay in Lane

62

ElliotJLT/Claude-Skill-Potions

Before making changes, verifies they match what was actually requested. Activates when about to modify files, add features, or refactor code. Catches scope creep before it happens - no "while I'm here" improvements.

Software Development

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.