We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
or{}
1 parent 4e760c7 commit 2202ee5Copy full SHA for 2202ee5
vlib/v/tests/option_in_loop_test.v
@@ -0,0 +1,36 @@
1
+fn opt_0_10_20(x int) ?int {
2
+ if x < 0 || (x >= 10 && x <= 20) {
3
+ return error('invalid')
4
+ }
5
+ return x
6
+}
7
+
8
+fn test_options_in_for_loop_break() {
9
+ mut sum := 0
10
+ mut nbreaks := 0
11
+ for i := 5; i < 15; i++ {
12
+ x := opt_0_10_20(i) or {
13
+ nbreaks++
14
+ break
15
16
+ sum += x
17
+ // println('i: ${i:3} | sum: ${sum:3}')
18
19
+ assert nbreaks == 1
20
+ assert sum == 35
21
22
23
+fn test_options_in_for_loop_continue() {
24
25
+ mut ncontinue := 0
26
+ for i := -5; i < 30; i++ {
27
28
+ ncontinue++
29
+ continue
30
31
32
33
34
+ assert ncontinue == 16
35
+ assert sum == 270
36
0 commit comments