If, Else, and Other Conditionals that Exist

Hello fellow coding newbies. I decided to do my first ever blog post about a topic that I, myself, have struggled with as a new student of coding. Being new to Ruby, the conditional statement can be a confusing topic to grasp.

decisions, decisions, decisions

As ruby processes our code it moves in a single direction reading and responding to our code line by line. But sometimes, we want the program to “pick a side” based on conditions that we set. We can do this with some ‘if’ (conditional) statements. This can be similar to a regular “human” language. If some condition is true, then run this code.

if the current temperature is below 35 write “it’s freezing out there!”

Don’t forget to close your ‘if’ statements with an ‘end’.

Adding an ‘else’ in there can really can spruce your statement up, and this is when “decision making” begins to happen.

otherwise write “its not so cold out there”

Want to throw in another layer of decision making? Just drop in an ‘elsif’ in between the ‘if’ and ‘else’ and see what the program spits out.

In this case, our program will not know the temperature outside. We can use as many ‘elsif’ statements as we want and have a bunch of conditions to choose from.

If statements can be a great resource to put a variety of situations and variables to the test to achieve your desired output.

In this situation I am iterating through all of the students and comparing to a particular student, iterating through all the boat tests and comparing that to a specific test. I am then asking the program, did this particular student take this specific test before? If so, we can change the status of this student’s boat test to “passed”. If not, create a new ‘boat test’ instance where this student is considered “passed”.

Happy coding fellow coders, and don’t forget your ‘ends’!!!




Software engineering student, string cheese enthusiast!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Is Your Website Global?

Jump First, Dive Second, Surface Last

How to SAML federate your Azure account with G Suite

The Linuxist and the Windowsist

Easy distributed joins with Pachyderm

The Momentum Cross Trading Strategy — An Introduction.

Dynamically select orchestrators in Azure Durable Functions

AMA with John A. on teaching full-stack web development at Galvanize

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yevgeniy Valdman

Yevgeniy Valdman

Software engineering student, string cheese enthusiast!

More from Medium

To be continued…

One Hundred Subs and still Emerson Echoes

My Stream Gifs