CONVERSION REFERENCE

Control flow, loops, and scope

The active converter supports proved conditionals and bounded loop forms, including exact Python loop-else completion.

Conditionals

if/elif/else is admitted when each condition has a proved truth representation and branch results remain inside the static type and lifetime rules.

Publishing a branch-defined scalar

A fresh bool, int, float, or str local may first be assigned inside conditional arms and used afterward when every reachable continuation stores a compatible representation before any read. Nested branches and a continuing branch after a sibling return are reachability-aware.

def classify(value: int) -> int:
    if value < 0:
        result = -1
    elif value == 0:
        result = 0
    else:
        result = 1
    return result

Converted behavior:

The C local is declared once at function entry without a synthetic value. Source-ordered assignments remain in their original branches.

The binding rejects when a reachable path lacks a store, a read can occur before the first store, arms disagree on representation, or the candidate is a container, record, loop-lifetime value, captured value, global, or nonlocal.

While loops

def drain(count: int) -> int:
    while count:
        count = count - 1
    else:
        return 1
    return 0

The else suite runs when the condition becomes false, including when the first condition is false. A break owned by the same loop suppresses the suite.

Positional range loops

Supported forms are range(stop), range(start, stop), and range(start, stop, step). Arguments are positional and require stable integer representations. An explicit step is a nonzero integer literal. The target is one fresh name with a bounded lifetime.

def find_three(limit: int) -> int:
    result = -1
    for index in range(limit):
        if index == 3:
            result = index
            break
    else:
        result = 0
    return result

Range lowering guards the signed-64 induction update before adding the step. Crossing INT64_MAX or INT64_MIN selects the staged stop value rather than invoking undefined C signed overflow.

Fixed-container iteration

def sum_then_mark() -> int:
    values = [1, 2, 3]
    total = 0
    for value in values:
        total = total + value
    else:
        total = total + 1
    return total

Exact loop completion

Zero-iteration lifetime. A range or container loop target is not guaranteed to exist when the loop executes zero times. Reading that target from else or after the loop rejects unless its lifetime is independently safe. Initialize a separate result before the loop.

Rejected loop shapes

range keywords, zero or dynamic steps, multiple or destructuring targets, mutation or reuse of the active range target, general iterables, comprehensions, generators, and loop-local values escaping an unproved lifetime are outside the active contract.