summaryrefslogtreecommitdiff
path: root/tests/typ/code/while.typ
blob: acf7951e34f98566fb33fb30ac86f2c661056d1c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Test while expressions.

---
// Should output `2 4 6 8 10`.
#let i = 0
#while i < 10 [
    { i += 2 }
    #i
]

// Should output `Hi`.
#let iter = true
#while iter {
    iter = false
    "Hi."
}

#while false {
    dont-care
}

---
// Value of while loops.
// Ref: false
#test(type(while false {}), "template")
#test(type(while false []), "template")

---
// Condition must be boolean.
// Error: 8-14 expected boolean, found template
#while [nope] [nope]

// Make sure that we don't complain twice.
// Error: 8-15 unknown variable
#while nothing {}

// A single error stops iteration.
#let i = 0
#test(error, while i < 10 {
    i += 1
    if i < 5 [nope] else { error }
})
#test(i, 5)