For with a specified step

for(;;) loop:

for (var i = 2; i <= 8; i += 2) {
    say i
}

for-in loop:

for i in (2 .. (8, 2)) {
    say i
}

.each method:

2.to(8).by(2).each { |i|
    say i
}

Last updated