summary refs log tree commit diff
path: root/Test/A07control.ztst
blob: b9b89b58805c7c0fc3405759f1b61921ff22eab9 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Test control commands for loops and functions.

%test

  fn3() { return $1; print Error }
  fn2() { fn3 $1 }
  fn() {
    print start $1
    fn2 $1
    return
    print Error
  }
  for val in -1 0 1 255; do
    fn $val; print $?
  done
0:Passing of return values back through functions
>start -1
>-1
>start 0
>0
>start 1
>1
>start 255
>255

  fn() {
    continue
  }
  fn
1:continue outside loop
?fn:continue:1 not in while, until, select, or repeat loop

  for outer in 0 1 2 3; do
    print outer $outer
    for inner in 0 1 2 3; do
      print inner $inner
      continue $(( (outer & 1) ? 2 : 1 ))
      print error
    done
    print outer end
  done
0:continue with valid argument
>outer 0
>inner 0
>inner 1
>inner 2
>inner 3
>outer end
>outer 1
>inner 0
>outer 2
>inner 0
>inner 1
>inner 2
>inner 3
>outer end
>outer 3
>inner 0

  for outer in 0 1; do
    continue 0
    print -- $outer got here, status $?
  done
1:continue error case 0
?(eval):continue:2: argument is not positive: 0

  for outer in 0 1; do
    continue -1
    print -- $outer got here, status $?
  done
1:continue error case -1
?(eval):continue:2: argument is not positive: -1

  fn() {
    break
  }
  for outer in 0 1; do
    print $outer
    fn
  done
0:break from within function (this is a feature, I disovered)
>0

  for outer in 0 1 2 3; do
    print outer $outer
    for inner in 0 1 2 3; do
      print inner $inner
      break $(( (outer & 1) ? 2 : 1 ))
      print error
    done
    print outer end
  done
0:break with valid argument
>outer 0
>inner 0
>outer end
>outer 1
>inner 0

  for outer in 0 1; do
    break 0
    print -- $outer got here, status $?
  done
1:break error case 0
?(eval):break:2: argument is not positive: 0

  for outer in 0 1; do
    break -1
    print -- $outer got here, status $?
  done
1:break error case -1
?(eval):break:2: argument is not positive: -1