02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

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!

Overview

We'll look at the drawbacks and lack of flexibility of the if-else and else-if construct, and propose an alternative which is more flexible and powerful

01:59

Switch

We'll introduce you to the switch construct, explaining how it can be used to make decisions based on checking and comparisons using a single identifier

06:59

Breaking The switch Down

We'll discover and describe in detail the importance of using break statements in switch cases, and the pitfalls if we forget/choose not to do so. Let us learn about the break keyword in detial

11:06

Switch In Action: Days Of The Month

We will see a few code examples in as3 to illustrate certain programming logic which can be implemented very easily and concisely using switch constructs

13:09

What if Can't Do...

We'll see unique programming logic which is elegantly and efficiently achieved using switch constructs, but are next to impossible with if constructs

09:17

The Ternary Operation (:?)

Enhancing the readability of code and introducing efficiency for simple decision making scenarios using ternary operator ?: We will also learn the syntax for using ternary operator

07:39

The Ternarator

In this video, we will see how to use ternary operator for complex conditionals. We will compare it by if conditional and discuss the necessity for understanding the concept and its implementation in

06:53