3 ms·
Nothing per se, but more declarative code is often nicer to look at than imperative code. In the for loop example, you need to name and explicitly initialize a
by cygx 6y ago
Nothing per se, but more declarative code is often nicer to look at than imperative code.
In the for loop example, you need to name and explicitly initialize a variable, you need to explicitly write down the comparison, and you need to explicitly increment the variable.
In the Ruby example, the plumbing is hidden from view, and you can just tell the runtime how often you'd like the thing to happen.
On a tangential note, in Raku (the language formerly known as Perl6), you could have written that as
say("Hello world") xx 10;
That's pretty hard to beat, imo.