-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
iteration.mon
34 lines (30 loc) · 758 Bytes
/
iteration.mon
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
// Iterating over the contents of an array
puts( "Array: value\n")
a = [ "My", "name", "is", "Steve" ]
foreach item in a {
puts( "\t", item , "\n");
}
puts( "Array: index/value\n")
foreach index, item in a {
puts( "\t", index, "\t", item , "\n");
}
// Iterating over the contents of a string.
puts( "String: value\n")
foreach char in "Steve Kemp" {
puts( "\t", char , "\n");
}
// character + index
puts( "String: index/value\n")
foreach idx, char in "Steve Kemp" {
puts( "\t", idx, "\t", char , "\n");
}
// Iterating over a hash
h = { "Foo": "Bar", "Steve": "Kemp"}
puts( "Hash: key\n")
foreach key in h {
puts( "\t", key, "\n");
}
puts( "Hash: key/value\n")
foreach key,val in h {
puts( "\t", key, "\t=>\t", val, "\n");
}