The reason that there are so many languages (and no perfect one) can perhaps be summed up best by XKCD:
It's not dealing with languages, but it explains beautifully how many languages, including Ruby, began. Someone was dissatisfied with the current selection, thought it needed some definitive readjustment, and added to the ~1500 languages which exist today. And there can't be a perfect language for the reason that you have to give to get, where to acquire convenience you have to sacrifice speed and precision (which is why Python is so much slower than C), to become more versatile you have to become less exact (Java vs. Perl), and Basic, despite being able to do just about anything, isn't ever used anymore.
Anyways, onto some actual code.
Ruby has full support for all standard loop types, and has relatively simple syntax. Here's an example of for loops:
Note that two dots make the variable go one step farther, while three produce the more traditional result. The "#{}" thingy is pretty much string concatenation, where it will just put whatever i happens to be there. Note also that the return value is the loop range, with the dots still preserved.
While loops are also quite simple:
Note that there's a "do" at the end of the while line, and that it returns a nil.
Here's an until loop, to show the slight difference:
And a wild Collatz Conjecture appears! Note the lovely nested conditional and the return of nil.
Moving out of a line editor, one finds themselves in the labyrinth of disagreeing sites, all trying to explain why their way is the best. This one, however, managed to get everything working properly: http://railsapps.github.io/installrubyonrails-mac.html, and this one directed me to Atom: https://learnrubythehardway.org/.
I then downloaded Atom at https://atom.io/, and as such a simple file like:
can be run with:
but note the lack of a return.
Nice blog! It was interesting to see the difference in syntax between languages (yours being Ruby, mine being Boo). I though that the ... and .. were interesting. In my language in a for loop,we would say "for i in range(0,10)
ReplyDeletecode"
It is interesting to see how there are so many different languages all being able to produce the same output, but in different ways! Great blog!