3 ms·
Right, what's wrong with just for (var i = 0; i < 1000; i++) { console.log("Hello world"); }
by suby 6y ago
Right, what's wrong with just
for (var i = 0; i < 1000; i++) {
console.log("Hello world");
}
- cygx 6y agoNothing 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.