Post Two: The Basics
Given that Ruby is, in fact, a programming language, it can handle things like math, variables, conditionals, and loops. In Ruby, math is very similar to other sorts of math. You can see some ramblings of what works and doesn't work here:
And there you go. It's pretty intuitive, although I did expect logs to be a little bit different. If you want a particular base, you just do this:
And everything works out well in the end. Variables are also easy, like so:
And conditionals are written like this:
While for loops look like this:
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.
Next time, I'll get the file system working so that irb(main): stops showing up and I'll be finally able to edit my mistakes!
Anyways, 'twas fun, and see you some time before the twelfth!
Jamie
The syntax is fascinating for this language. In python writing loops is similar to that in java. Also, python doesn't have an "until" loop, instead it has while loops. Also it doesn't have "#{}" instead it has other ways to perform similar functions. This is pretty interesting though.
ReplyDelete