Skip to content

Commit 66d6282

Browse files
committed
Add control-flow examples for while until and loop control
1 parent 8f5ed9b commit 66d6282

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

ROADMAP.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Goal: improve language ergonomics for complex script logic and recovery behavior
233233
- [x] Add parser/runtime tests for each new control flow construct.
234234
- [x] Add nested control flow tests for edge cases.
235235
- [x] Add docs updates in `docs/control-flow.md` and `docs/errors.md`.
236-
- [ ] Add examples under `examples/control_flow/` for each new feature.
236+
- [x] Add examples under `examples/control_flow/` for each new feature.
237237

238238
### v0.16.0 Definition of Done
239239

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
def odds_below(limit)
2+
out = []
3+
n = 0
4+
while n < limit
5+
n = n + 1
6+
if n == limit
7+
break
8+
end
9+
if n % 2 == 0
10+
next
11+
end
12+
out = out + [n]
13+
end
14+
out
15+
end
16+
17+
def run()
18+
odds_below(10)
19+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def collect_until(limit)
2+
out = []
3+
n = 0
4+
until n >= limit
5+
out = out + [n]
6+
n = n + 1
7+
end
8+
out
9+
end
10+
11+
def run()
12+
collect_until(5)
13+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def countdown(start)
2+
out = []
3+
n = start
4+
while n > 0
5+
out = out + [n]
6+
n = n - 1
7+
end
8+
out
9+
end
10+
11+
def run()
12+
countdown(5)
13+
end

0 commit comments

Comments
 (0)