shelly-shell 0.5.4

A Rust based Unix style shell with a typed and structured language syntax.
# Control flow

## Conditional values

`if` is both a statement and a value expression. Conditions use the language's
truthiness rules. Braces are required.

<!-- example: CONTROL-IF -->
```shy
let $stock = 3
let $label = if $stock == 0 { "sold out" }
    else if $stock < 5 { "limited" }
    else { "available" }
echo $label
```

```text
limited
```


Only the selected body runs. Branches create scopes. An `if` without a selected
branch or fallback produces `()`. Valid syntax is required in all branches.

## `for` and destructuring

<!-- example: CONTROL-FOR -->
```shy
for ($name, $minutes) in [["stretch", 5], ["walk", 20]]
{
    echo $name $minutes
}
let $visits = 0
for _ in 0..3 { $visits = $visits + 1 }
echo $visits
```

```text
stretch 5
walk 20
3
```


`_` discards a binding. Flat destructuring requires the exact item length. A hash
can use the same two-position pattern. See [iteration](Ranges-and-Iteration) for
source snapshots and custom iterators.

## Repetition

<!-- example: CONTROL-LOOPS -->
```shy
let $remaining = 2
while $remaining > 0 { $remaining = $remaining - 1 }
until $remaining == 2 { $remaining = $remaining + 1 }
loop
{
    $remaining = $remaining + 1
    if $remaining == 3 { continue }
    break
}
echo $remaining
```

```text
4
```


`while` repeats while its condition is true; `until` repeats while false.
Both check before the first body. `loop` has no condition.

`break` exits the innermost loop in the current execution frame. `continue`
starts its next iteration. Neither accepts a value or a label, and a called
function cannot break its caller's loop. Scope unwinding and `finally` still apply.

`return` leaves the current function. Use [error handling](Errors-and-Cleanup)
when recovery, rather than loop control, is needed.

---

Related: [Match and type guards](Match-and-Type-Guards) ยท [Numbers and logic](Numbers-and-Logic)