We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Thank you for communicating respectfully with me as an adult. Yes it is needed.
If your question is in reference to the need for the logical check inside of it (else-if vs else), the reason is that you need to convert 12AM (midnight) to 00; we already know that it's AM because it failed the if(PM) check in the previous line, so we just need to check if the hour is 12.
If your question is in reference to the reason/benefit of using an else-if over if, it's because each input is binary in that it will always be either AM or PM. Having if(PM) = true means that the logical flow completely ignores the else-if code when if(PM) = true, thus eliminating the need to run another redundant logic check if(AM) at every single execution. It essentially removes two unneeded logical comparisons from each execution (compared to original poster's logic) of the code; while it won't make a big difference here, it certainly makes a difference in the real world.
Time Conversion
You are viewing a single comment's thread. Return to all comments →
Thank you for communicating respectfully with me as an adult. Yes it is needed.
If your question is in reference to the need for the logical check inside of it (else-if vs else), the reason is that you need to convert 12AM (midnight) to 00; we already know that it's
AM
because it failed theif(PM)
check in the previous line, so we just need to check if the hour is 12.If your question is in reference to the reason/benefit of using an else-if over if, it's because each input is binary in that it will always be either
AM
orPM
. Havingif(PM) = true
means that the logical flow completely ignores the else-if code whenif(PM) = true
, thus eliminating the need to run another redundant logic checkif(AM)
at every single execution. It essentially removes two unneeded logical comparisons from each execution (compared to original poster's logic) of the code; while it won't make a big difference here, it certainly makes a difference in the real world.