2023-10-29 23:31:06 +00:00
|
|
|
# Function
|
|
|
|
x = "bar"
|
2023-10-06 12:17:37 +00:00
|
|
|
|
2023-10-29 23:31:06 +00:00
|
|
|
func = function <> {
|
|
|
|
x = "foo"
|
|
|
|
x
|
|
|
|
}
|
2023-10-06 12:17:37 +00:00
|
|
|
|
2023-10-29 23:31:06 +00:00
|
|
|
assert_equal("foo", (func))
|
|
|
|
assert_equal("bar", x)
|
2023-10-06 12:17:37 +00:00
|
|
|
|
2023-10-29 23:31:06 +00:00
|
|
|
# For Loop
|
|
|
|
x = 42
|
2023-10-06 12:17:37 +00:00
|
|
|
|
2023-10-29 23:31:06 +00:00
|
|
|
for number in [1 2 3] {
|
|
|
|
x += number
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_equal(48, x)
|
|
|
|
|
|
|
|
# Async Loops
|
|
|
|
|
|
|
|
## Transform Loop
|
|
|
|
|
|
|
|
x = 42
|
|
|
|
y = [1 2 3]
|
|
|
|
|
|
|
|
transform number in y {
|
|
|
|
number += x
|
|
|
|
x = 1000
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_equal([43, 44, 45], y)
|
|
|
|
assert_equal(42, x)
|
|
|
|
|
|
|
|
## Filter Loop
|
|
|
|
|
|
|
|
x = 42
|
|
|
|
y = [1 2 3]
|
|
|
|
|
|
|
|
transform number in y {
|
|
|
|
number += x
|
|
|
|
x = 1000
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_equal([43, 44, 45], y)
|
|
|
|
assert_equal(42, x)
|
|
|
|
|
|
|
|
## Filter Loop
|
|
|
|
|
|
|
|
x = 42
|
|
|
|
y = [1 2 3]
|
|
|
|
|
|
|
|
filter number in y {
|
|
|
|
number += x
|
|
|
|
x = 1000
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_equal([43, 44, 45], y)
|
|
|
|
assert_equal(42, x)
|