Conditionals!
Okay. So, yesterday I spent my time reading how to code conditional statements in Ruby. Because I do have a limited exposure to programming, this isn’t actually as bad as it sounds (or as it could be).
Basically, a common interaction for a program involves the computer stating that IF some condition is met, this happens—ELSE (the condition is not met) this other things happens. While I hate to take examples directly from Why’s (poignant) guide to Ruby (haven’t I already linked to this site enough?), the below code snippet does a great job of explaining several parts of a conditional statement way better than I ever could… besides, I’m the student, not the teacher, right?
print( if at_hotel.nil?
“No clue if he’s in the hotel.“
elsif at_hotel == true
“Definitely in.“
elsif at_hotel == false
“He’s out.“
else
“The system is on the freee-itz.“
end )
So, in this example, if at_hotel is empty (nil) then “No clue if he’s in the hotel.” will be printed to the screen. This means that the program doesn’t have enough info to answer the question. If at_hotel is TRUE, then it will print “Definitely in.” If at_hotel is FALSE, then “He’s out.” gets printed. Since this covers all the possibilities, the only other option is that system must be on the fritz.
Conditional statments aren’t so bad, right? In fact, everything has been pretty manageable up to this point. I have to admit that I’m getting worried, because in my past experience, this is around the time that the hammer usually drops. Usually at this point in the training, the next bit of code we see is so complicated and unrelated to anything we’ve learned, that it causes my eyes to cross and my brain to shut down. Hopefully that won’t be the case this time…