Skip to content

Commit b676ac4

Browse files
committed
Update tutorial
Signed-off-by: Louis Mandel <[email protected]>
1 parent 2fb745d commit b676ac4

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

docs/tutorial.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ This results in the following output:
794794
{"Bob": 1, "Carol": 2, "David": 3, "Ernest": 4}
795795
```
796796

797-
### While Loop
797+
### Other loops
798798

799799
The following example shows a while loop in PDL:
800800

@@ -804,8 +804,14 @@ The following example shows a while loop in PDL:
804804

805805
The `while` field indicates the looping condition and `repeat` contains the body of the loop.
806806

807-
Notice that `for`, `while`, `until`, and `maxIterations` can all be combined in the same `repeat` block. The loop exits
808-
as soon as one of the exit conditions is satisfied:
807+
This loop can be rewritten using `max_iterations` to bound the number of iterations and `index` to name the iteration number.
808+
809+
```yaml
810+
--8<-- "./examples/tutorial/loop_index.pdl"
811+
```
812+
813+
814+
Notice that `for`, `while`, `until`, and `max_iterations` can all be combined in the same `repeat` block. The loop exits as soon as one of the exit conditions is satisfied:
809815

810816
```yaml
811817
--8<-- "./examples/tutorial/repeat.pdl"

examples/tutorial/loop_index.pdl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
index: i
2+
repeat:
3+
text: ${i + 1}
4+
max_iterations: 3

examples/tutorial/repeat.pdl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
description: repeat loop with multiple conditions
22
defs:
33
numbers:
4-
data: [1, 2, 3, 4]
4+
data: [42, 2, 4012, 27]
55
names:
66
data: ["Bob", "Carol", "David", "Ernest"]
77
for:
88
number: ${ numbers }
99
name: ${ names }
10+
index: i
1011
repeat:
11-
"${ name }'s number is ${ number }\n"
12+
"${i}: ${ name }'s number is ${ number }\n"
1213
until: ${ name == "Carol"}
13-
max_iterations: 1
14+
max_iterations: 3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Bob's number is 1
1+
0: Bob's number is 42
2+
1: Carol's number is 2
3+

0 commit comments

Comments
 (0)