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’!!!
Halo wenzangu coding newbies. Niliamua kufanya chapisho langu la kwanza la blogi juu ya mada ambayo mimi mwenyewe nimepambana nayo kama mwanafunzi mpya wa programu. Kuwa mpya kwa Ruby, taarifa masharti inaweza kuwa mada ya kuchanganyikiwa kuelewa. Kama ruby taratibu code yetu ni hoja katika mwelekeo mmoja kusoma na kujibu code yetu mstari kwa mstari. Lakini wakati mwingine, tunataka programu "ichague upande" kulingana na hali ambazo tumeweka. Tunaweza kufanya hivyo kwa baadhi ya <unk>if<unk> (sharti) taarifa. Hii inaweza kuwa sawa na lugha ya kawaida ya "binadamu". Kama baadhi ya hali ni kweli, kisha kukimbia kanuni hii. Usisahau kufunga taarifa yako ya "kama" na "mwisho". Kuongeza "nyingine" huko kwa kweli inaweza inaweza spruce taarifa yako juu, na hii ni wakati "kufanya maamuzi" huanza kutokea. Unataka kutupa katika safu nyingine ya maamuzi? Tu kushuka katika <unk>elsif<unk> kati ya <unk>if<unk> na <unk>else<unk> na kuona nini programu spits nje. Katika kesi hii, programu yetu haitajua joto nje. Tunaweza kutumia kama wengi <unk>elsif<unk> taarifa kama tunataka na kuwa na kundi la masharti ya kuchagua kutoka. Kama taarifa inaweza kuwa rasilimali kubwa ya kuweka aina ya hali na vigezo kwa mtihani ili kufikia pato lako taka. Katika hali hii mimi ni iterating kupitia wanafunzi wote na kulinganisha na mwanafunzi fulani, iterating kupitia vipimo vyote mashua na kulinganisha kwamba kwa mtihani maalum. "Kisha, mtafiti anauliza, ""Je, mwanafunzi huyu wa kwanza alishiriki mtihani huu wa kwanza?""" Kama ni hivyo, tunaweza kubadilisha hali ya mtihani wa mashua ya mwanafunzi huyu kuwa <unk>kupitisha<unk>. Kama si, kuunda mpya <unk>boat mtihani<unk> mfano ambapo mwanafunzi huyu ni kuchukuliwa <unk>kupitisha<unk>. Happy coding wenzake coders, na usisahau <unk>ends<unk> yako!! !