For

for(;;) loop:

for (var i = 1; i <= 5; i++) {
    for (var j = 1; j <= i; j++) {
        print '*'
    }
    print "\n"
}

for([]) loop:

for (1..5) { |i|
    for (1..i) { print '*' }
    print "\n"
}

for-in loop:

for i in (1..5) {
    for j in (1..i) { print '*' }
    print "\n"
}

Idiomatic:

5.times { |i|
    i.times { print '*' }
    print "\n"
}

Last updated