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

Overview

The purpose of programming is to translate logic into a computer language. In a sense we are trying to teach the computer to think for us. As you started this course with us and followed a few steps in the process to become a developer, this is probably already clear to you. The really hard question that remains unanswered is how do you teach a computer to do things? How do you teach a metal object to think? (We can enlighten you about one method that does NOT work! A short while ago, one of our computers kept crashing. It happened so often we finally gave it a good kick! Good and bad news: it never crashed again. Then again, it never ran again either. ;)

Logic is about making decisions based on input or other conditions. When a program "decides" something based on a question, we call it a "conditional." Conditionals are commonly used to ask questions in Flash and in programming in general. There are two types of conditionals: if () and switch (). In this hour we will focus on the following various types of if () conditionals:

if:

When there is only one decision to be made, without alternatives. This is the most simple form of condition testing in program logic. (If it's Friday night, it's time to go out.)

if-else:

When you have a choice in a decision, but only one. (If it's Friday night, go out; else be a deadbeat.) The next simple category of decision making

if/else if/else:

When you have several different decisions to make, but all at the same level of choices… it is nothing but an extended if-else construct where the number of conditions to be checked is more than one. (If it's Thursday night, start wishing it was Friday. If it's Friday night, go out. Both of those are on the same level: the logic hits the Thursday if, then flows to the Friday if.)

Nested if statements:

If there are more than one criteria for a decision (requiring 2 levels: easier than it sounds! If it's Friday night, if you're thirsty, go out. The thirsty if is nested inside the Friday one: unless it's Friday, you'll never wonder if you need a drink or not.) Generally used when we have more than one criteria that are independent.

Testing for negation:

Sometimes we can simplify the logical expression by testing for the occurrence of its complement: testing to check if it's NOT true. (What if we're boring souls, and we only ever go out on Fridays, and we are desperate so we check every single day – if it's Monday, stay sober. If it's Tuesday, stay sober.... just to see if it's Friday? The easier (and faster, slicker) way would be to check if it's NOT Friday!)

These statements are implemented in the program using special language constructs that we will explore in the next session.

Overview

We will learn about various conditionals related to ‘if’. The main focus is on the importance of brackets and conditionals such as if/else, if/else if…, nested if, if not etc.

04:14

Conditionals and Operators

Greater than the tutorials you'll find elsewhere, 02geek takes less time to teach how logical operators are directly linked to conditionals, and how conditional expressions can be formed using these o

04:49

if

We introduce the “if” construct and show how it can be used for making programming decisions while implementing the program logic

04:30

Brackets

We explain the importance of using brackets with if, mainly to combine a sequence of operations, all to be performed on the same condition

07:41

else

We introduce the language mechanism for providing alternatives in code; ie,. to make decisions when we have 2 options

07:29

Else-if: dealing with multiple conditions

We introduce the else-if construct, to help make logic decisions when more than 2 options are available

08:41

Nested if conditional construct

We introduce the nested if construct, useful when there are more than one criteria of decision making, including one inside another

09:08

Nested if’s – The Answer

We introduce another approach to nested if’s organization: mainly inverting the nesting levels of if constructs

04:44

Say it ain't so – the “If-Not” conditional

We introduce how to reorganize condition checking code using if constructs having Not (!) operators in the conditionals

02:38