Overview
In this set of summaries on conditionals, we'll focus on the language 'switch' construct. Apparently the name of the construct, "switch," does scare away a lot of novice or beginner programmers. One can only attribute this "fear" to the choice of the English word used to name it. In other words, we use "if" and "else" in everyday English communication, so it's very intuitive.
The "switch" keyword reminds us of our parents nagging at us to turn off light switches when not in use, while we were kids! We are no longer kids (or at least that's what all of us want to believe,) so let's get on with it. The switch construct is here to stay, and if we want to be prolific programmers, we better know how to use it and how to use it well.
Another topic we intend to discuss in this set of summaries is the ternary operator, and this language construct scares away not only novice programmers, but experienced ones as well! To be frank it does look cryptic, since right from childhood, we are exposed only to unary and binary logical (while learning Math) and arithmetic operators. So the ternary operator does not appear natural, or intuitive. But as we'll soon discover, this operator has the potential to cut down on the lines of code one must write to express a 2-way decision making construct. Just keep this in the back of your mind: the ternary operator is a magic fairy that can produce the result of a 2-way choice in a jiffy. Only you need to invoke the fairy calmly and carefully, so as not to upset her!
So, we hope you're all set to dive head-first into the fascinating world of conditionals-2, with a slightly different approach and rephrasing of syntactical elements to achieve the same results as the if-else clauses. Let's start right away!
Ready to Level Up Your Skills?
Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!
Enroll Now for Free!