02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext 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.

Video Transcript

00:00congratulations you have just reached hour number five and that's really really exciting
00:04and this hour is titled conditionals part one uh before we start going into conditionals let's
00:09just make sure are you worthy of this fifth hour are you ready for it well if you know what variables
00:15are and you already have a very solid understanding of what primitive variables are if it's numbers
00:20if it's bullions if it's strings you're comfortable with them not only you're comfortable with them
00:25you're also comfortable with operators very very important you'll be comfortable with operators
00:29as the next topic is all about the next level after operators so if you feel that you are and if
00:35you're not sure you could always go to everything i feel like.com and take one of our tests or
00:39preferably a few of them just to get more comfortable now after you took those tests and you're back
00:44i even recommend you take a test of this course before you even watch just to get a feel about
00:48what the topics are going to be so what are we going to be learning about in this first hour
00:53of conditionals we're going to be focusing about conditionals we're going to talk about
00:57something that's called if and we're going to talk about else now what is if what is else in
01:02a nutshell if is basically sometimes at some point in code just as in life you reach a scenario
01:08where only if a certain condition happens which that connects that are operators if a certain
01:13condition happens such as a condition that happens with our bullions then we'll do one thing
01:19that's our if now otherwise we'll do another thing so we're going to look at that we're
01:22going to look at the syntax we're going to look at how to do it on top of that we're
01:25going to take a look at if and else if so sometimes it's not black and white sometimes it's not yes or
01:31no sometimes it's red green yellow blue sometimes there's there's a few options now when there's a
01:37few options when it's not only or this or that then we start going into a world of else if
01:42if else if else if you can have a few of them so it's if this condition doesn't mean then
01:47it asks this condition if this doesn't it doesn't mean then you can have another one
01:51and so on and so forth and we're going to look at the syntax we're going to look at the
01:55implementation of it we're going to talk a little bit more about brackets because brackets are a very
02:00very important part of programming and we're going to look we're going to see brackets over
02:04and over and every single every single hour they're going to have another usage and another usage
02:08so we're going to look at brackets we're going to see what their usage is in this video and so
02:12this only we're going to realize a pattern and i really really encourage you strongly to notice
02:17these brackets and they're very very important and they're gonna make your
02:20coding experience so much easier if you respect them and you pay attention to
02:23them and you don't let them be automated and you don't ignore them. Now
02:27the next topic that we're gonna cover is a topic that's gonna
02:30overlap what we've just done right here. Sometimes you want to have nested ifs
02:34and we're gonna look and talk about what nested ifs are but nested
02:38ifs are ifs that are inside of ifs. So if I'm saying like if you're home and
02:43if the kitchen is well if you're home now already you're in the house now if
02:48you're in the house I'm gonna ask you if you're in the bathroom do this if you're
02:51in that room do that right so just like in the real real world so instead of
02:56asking if this or that or that or that because else if is almost like saying
03:00or that it is or that. So in nested ifs we're gonna see how could we take
03:05advantage of putting if statements inside of if statements. Obviously you're not
03:09there yet if this sounds a little bit scary don't worry about it we're first
03:11gonna go through this which is gonna make this much easier and we're gonna
03:16wrap it all up by talking about how to ask if not. So we're gonna look at if not
03:23and it's gonna be a very very interesting topic how could we ask if
03:26not in flash and we will find that out in the next hour. So I really encourage
03:31you first of all congratulations for finishing so many hours you're already
03:35almost halfway there this hour is probably gonna put you in that half
03:39point and in this half point you should start feeling more confident and I'm very
03:44very excited for you guys and any any as always as always remember support exams
03:50community mix it up whatever order you want it to be ideally obviously community
03:55the more you interact with other people the better the exams are so critical
03:59they're gonna give you a lot of confidence as well and they're gonna
04:01scare you out to sometimes but that's good because if you don't really get
04:04something I want you to connect us in their community I want you to send us
04:07an email we want you to understand so good luck and hopefully we'll see you in
04:12the next hour

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!