Debian Codegraph @

terps/tads/tads3/test/data/foreach.t

raw
1 #include "tads.h"
2 #include "t3.h"
3 #include "vector.h"
4
5 main(args)
6 {
7 local i, vec;
8
9 args = ['hello', 'there', 'how', 'are', 'you', 'today'];
10
11 "Constant list:\n";
12 foreach(local x in args)
13 "<<x>>\n";
14 "\b";
15
16 args += '!!!';
17 "Non-constant list:\n";
18 foreach (i in args)
19 "<<i>>\n";
20 "\b";
21
22 i = 1;
23 vec = new Vector(10).setLength(10).applyAll({x: i++});
24
25 "Vector:\n";
26 foreach(i in vec)
27 "<<i>>\n";
28 "\b";
29
30 "Vector, modifying throughout foreach:\n";
31 i = 1;
32 foreach(local x in vec)
33 {
34 vec.applyAll({v: v+1});
35 "x = <<x>>, vec[<<i>>] = <<vec[i]>>\n";
36 ++i;
37 }
38 "\b";
39 }