LearnMusi for DevelopersMusi for Python DevelopersBlocks, Control Flow, and Repetition

Blocks, Control Flow, and Repetition

Read Blocks, Control Flow, and Repetition as a Python habit shift, with links to the Musi Book definition.

A Python reader brings habits from names, dictionaries, classes, protocols, exceptions, None, imports, and duck typing. That helps with code around domain words before machinery, but the Musi page asks a narrower question: what contract should this branching and block results example make visible?

python
def delivery_fee(distance_km: int) -> int:
    if distance_km == 0:
        return 0
    return 45

Reading Blocks, Control Flow, and Repetition from Python

On the Musi side, Musi blocks and matches are expressions when they produce a value; the branch answer matters more than the statement container. Read the shared example through Python eyes: keep the useful instinct, then let Musi name shape, behavior, absence, and outside work in separate places.

False friend

Do not carry over temporary variables whose only job was to smuggle a branch result out of a statement block. For a Python reader, the trap is trusting runtime convention where Musi expects a visible type or effect; Musi class is closer to an explicit protocol/typeclass than a Python class with attributes and methods.

When this pays off

Use this shape when a route fee, access decision, or small rule table chooses one value from several cases. The Python instinct still helps here: Keep the Python habit of naming the real-world thing first.

Keep close