Docs rewrite
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
---
|
||||
title: Control Flow
|
||||
description: If/else, while, for, c-style for, loop, match, break, continue, and return.
|
||||
icon: ArrowLeftRight
|
||||
---
|
||||
|
||||
### If/Else
|
||||
|
||||
```mist
|
||||
if condition {
|
||||
// body
|
||||
} else if other_condition {
|
||||
// body
|
||||
} else {
|
||||
// body
|
||||
}
|
||||
```
|
||||
|
||||
Conditions must be parenthesized: `if (expr) { }` or `if expr_no_struct { }` (struct literals require parentheses).
|
||||
|
||||
Used as an expression:
|
||||
|
||||
```mist
|
||||
let x = if true { 1 } else { 2 };
|
||||
```
|
||||
|
||||
### While
|
||||
|
||||
```mist
|
||||
while condition {
|
||||
// body
|
||||
}
|
||||
```
|
||||
|
||||
### For
|
||||
|
||||
```mist
|
||||
for pattern in iterator {
|
||||
// body
|
||||
}
|
||||
|
||||
for i in 0 .. 10 {
|
||||
// body
|
||||
}
|
||||
```
|
||||
|
||||
### C-Style For
|
||||
|
||||
```mist
|
||||
for (let mut i = 0; i < 10; i++) {
|
||||
// body
|
||||
}
|
||||
```
|
||||
|
||||
### Loop
|
||||
|
||||
```mist
|
||||
loop {
|
||||
// infinite loop
|
||||
}
|
||||
```
|
||||
|
||||
### Match
|
||||
|
||||
```mist
|
||||
match value {
|
||||
pattern1 => expr,
|
||||
pattern2 => {
|
||||
// block body
|
||||
}
|
||||
pattern3 | pattern4 => expr,
|
||||
}
|
||||
```
|
||||
|
||||
### Break / Continue
|
||||
|
||||
```mist
|
||||
break;
|
||||
continue;
|
||||
```
|
||||
|
||||
### Return
|
||||
|
||||
```mist
|
||||
return;
|
||||
return value;
|
||||
```
|
||||
Reference in New Issue
Block a user