#!/usr/bin/ruby

class MyRange(from, to) {
    method iter {
        var b = to;
        var i = from;
        func {
            i <= b ? i++ : nil
        }
    }
}

say '=> User defined range:'

var r = MyRange(1, 5)

for i in r {
    say i
}

say '=> User defined range with next:'

for i in MyRange(1, 8) {
    next if (i%2 == 0)
    say i
}

say '=> Array range:'

for i in [1,2,3] {
    say i
}

say '=> Array range with break:'

for i in [1,2,3,4,5,6,7,8] {
    say i
    break if (i == 3)
}

say '=> Array range with next:'

for i in [1,2,3,4,5,6,7,8] {
    next if (i%2 == 0)
    say i
}

say '=> Numeric built-in range:'

for i in range(0, 8) {
    next if (i%2 == 0);
    say i;
}

say '=> String built-in range:'

for i in range('a', 'f') {
    say i
}

say '=> Very big built-in numeric range:'

for i in range(1, 1e9) {
    say i;
    break if (i == 5);
}

say '=> Very big user-defined range:'

for i in MyRange(1, 1e9) {
    say i;
    break if (i == 5);
}

say '=> Prefix caret range:'

for i in ^100 {
    next if (i%2 == 0)
    say i
    break if (i == 7)
}
