Ranges
Usage
Imported from the upstream Vibescript examples at ranges/usage.vibe and runnable in the browser today.
Source
ranges/usage.vibe
# vibe: 0.2
def inclusive_range_sum(start, finish)
total = 0
for value in start..finish
total = total + value
end
total
end
def descending_range_collect(start, finish)
output = ""
for value in start..finish
if output == ""
output = value
else
output = output + "," + value
end
end
output
end
def range_even_numbers(start, finish)
output = ""
for value in start..finish
if value % 2 == 0
if output == ""
output = value
else
output = output + "," + value
end
end
end
output
end
def run
{
inclusive_sum: inclusive_range_sum(1, 10),
descending: descending_range_collect(5, 1),
evens: range_even_numbers(1, 20)
}
end
Output
Press run to execute run from this example.