| If |
if cond { } else if cond { } else { } |
No parentheses around condition, braces required |
| For-range |
for key, val in container { } |
Works on slices, arrays, maps, strings, channels |
| For-condition |
for cond { } |
No parens, equivalent to while |
| For-infinite |
for { } |
No condition = infinite loop |
| For-C-style |
for i := 0, i < n, i += 1 { } |
All three parts optional |
| Switch |
switch x { case 1: ... case 2: ... } |
No fallthrough by default, use fallthrough explicitly |
| Switch-capture |
switch v in value { case 1: ... } |
Binds the scrutinee |
| Expr-switch |
switch { case cond: ... } |
Like if-else chain |
| Defer |
defer expr |
Runs at scope exit (LIFO stack) |
| Branch |
break, continue, fallthrough |
Standard semantics |
| When |
when ODIN_OS == "darwin" { } |
Compile-time conditional |
| Return |
return val |
Explicit, multiple returns: return a, b, true |
| Or-else |
val := expr or_else fallback |
Unwrap Maybe(T) with default |
| Or-return |
val := expr or_return |
Unwrap Maybe(T) or return from proc |
| Type |
Syntax |
Notes |
| Struct |
struct { x: int, y: f64 } |
Value type, fields comma/semicolon separated, no inheritance |
| Struct literal |
MyStruct{ x = 1, y = 2.0 } |
Named field syntax, positional also works |
| Struct packing |
struct #packed{ x: u8, y: u32 } |
No padding between fields |
| Struct alignment |
struct #align(N) { x: u8, y: u32 } |
Minimum alignment N |
| Struct raw-union |
struct #raw_union { x: u8, y: u32 } |
Fields overlap in memory (like C union) |
| Union |
union { int, bool, string } |
Tagged by default -- runtime discriminates |
| Union literal |
union_val: union { int, bool } = 42 |
Implicitly tagged by assigned type |
| Union switch |
switch v in union_val { case int: ... } |
Type-safe destructuring, compiler checks exhaustiveness |
| Union maybe |
union #no_nil{ int, bool, string, } |
#no_nil excludes nil from valid variants |