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.
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.
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.
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’!!!