> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sensecode.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Control Flow

> if/else, while, for, break, continue — and how indentation replaces braces.

## Indentation, not braces

A block is `:` followed by either an indented group of statements, or (for
short bodies) a single statement on the same line. The lexer tracks
indentation itself and hands the parser clean `INDENT`/`DEDENT` tokens —
see [Indentation-Sensitive Lexing](/architecture/indentation-lexing) for
exactly how, if you're curious about the mechanism.

<Tip>
  Typing `{`, `}`, or `;` doesn't just fail silently or fall through to a
  generic parse error — the lexer recognizes them and raises a specific
  message pointing at the replacement ("Sense uses indentation for blocks,
  not `{ }`..."). This matters more than it sounds: it's aimed squarely at
  people (and LLMs) whose muscle memory defaults to C-family syntax.
</Tip>

## `if` / `else`

```sns theme={null}
if x > 10:
    print("big")
else if x > 0:
    print("small positive")
else:
    print("non-positive")
```

`else if` chains parse as nested `if` statements in the AST (the same
representation you'd get writing it as nested `if`/`else` blocks by hand) —
there's no special "elif" token.

## `while`

```sns theme={null}
i = 0
while i < 3:
    print(i)
    i = i + 1
```

## `for` — over arrays and strings

```sns theme={null}
for user in ["alice", "bob", "carol"]:
    print("notifying " + user)

for ch in "abc":
    print(ch)
```

`range(a)`, `range(a, b)`, and `range(a, b, step)` build an `Array<Int>` you
can iterate the same way:

```sns theme={null}
total = 0
for n in range(1, 6):
    total = total + n
print(total)   # 15
```

## `break` / `continue`

```sns theme={null}
for user in ["alice", "bob", "carol", "dave"]:
    if user == "carol":
        continue
    if user == "dave":
        break
    print("notifying " + user)
```

```txt theme={null}
notifying alice
notifying bob
```

## Multi-line expressions

Newlines and indentation are both suppressed inside `( )` and `[ ]`, so a
call or array literal can wrap across lines without any continuation
character:

```sns theme={null}
print(
    "a",
    "b",
)

xs = [
    1,
    2,
    3,
]
```

## Continue

<CardGroup cols={2}>
  <Card title="Arrays" icon="brackets-square" href="/language/arrays">
    Literals, indexing, mutation, and the built-in helpers.
  </Card>

  <Card title="Modules" icon="folder-tree" href="/language/modules">
    Splitting a program across files with `import`.
  </Card>
</CardGroup>
