Conditionals 1 - 'if'

53:53 AS3 FLA 9


Smooth Operator ( ??? );
WARNING: you did not complete all prerequisites of this course. To Complete prerequisites above, pass course Exam.
Computers have to be programmed in order to perform tasks and make decisions according to the user'sexpectations. In this course, we will focus on the decision-making part of programs. Programing languages provide constructs, and both logical and comparison operators. Results of computation can then be compared, combined and tested to implement branching (branching is a simple concept that sounds scary as do most programing terms! Take the 'if' construct: %u201CIf the dog needs to go out, let him out. Else he will pee on the floor.%u201D The dog's need to go out, being let out and the events that follow are one branch of this 'if'; the other is the dog being ignored, and the consequences that ensue.)

Act now while we have available seating

Our on line school is private, affordable and interactive with trainer support.
Act now save your seat before someone else takes yours.
Act now
Your Score Is
100% of our students have
higher scores.
Filter Videos Test your Skills

Getting started with conditionals

This course will provide you with the basic concept that all programming depends on: determining IF a condition is true or false. This concept goes deeply into computers themselves and how they function on the most basic level: the binary system of 0,1. In normal life we use the Decimal system: based on 1-10, of course. Counting in the binary system looks awful but is totally simple: just count in 1's and 0's! All computers function on 1,0: on, off, true, false. Testing for these conditions is, of course, simple, using the lovely IF statement.

Simple, and great fun to play with! Use your imagination. In real life, what can either be yes/no, on/off? A light switch for sure. How about a pick-up line in a bar? Does it work for you? Yes or No! Of course different actions occur depending on that 'condition'... we'll leave those to your imagination ;)

You are exploring the very guts of coding in this course. Everything else depends on this knowledge. Everything! We suggest you take the exam pronto, before taking the course. It will filter out what you do and don't know, and present you with a list of course videos you need to watch. Don't worry if you blow it: hey, that's why you're here.

Learning IF conditional is real fun

You're here to learn the basics of coding first, then move on to do more complicated coding. Shit I don't know the real steps to get to that game! That needs to go here. If you just tell me, I'll integrate in 2 seconds onto a real working game (which we code from scratch, like any other project!) You talk about MAJOR fun!

It all starts with conditionals: with that IF. Don't forget our community. There you'll find other students at various places %u2013 they're not only fun, but a great resource when you get stuck (you WILL get stuck: experienced programmers get stuck all the time. Main part of the fun is figuring out what went wrong!!) So, want to play with us? IF so, start right here (IF this is over your head, take the free Starting Point course for the first time or again!) All roads start with a single step.

The most common basic constructs are:

%u2022 If

%u2022 if-else

%u2022 if-else if-else

%u2022 Nested if, if-else and if-else if-else clauses

%u2022 Testing of negated conditions

This course has been designed for the novice programmer to understand the behavior of a program based on the flow into and out of these constructs. Though it may look complicated at the moment, we compare it to true-life situations, as you'll see. This makes it simple to understand, we promise!

In the real world, getting work done, either by oneself or by others, involves making both physical and mental decisions. With computers, it's no different. But computers are incapable of acting on their own; we have to provide all the possible decisions to make them work for us. Together with computation, such decision making comprises %u201Ccomputer programming,%u201D which is accomplished by implementing logic in a programming language. In this section, we shall focus mainly on the decision-making constructs of the language, and they really are easy to understand. A few examples and code samples will set you on your way!

What is decision making?

The term used for %u201Cdecision making%u201D in computer programming is often called %u201Cbranching%u201D. In modern computers, logical branching is boolean in nature; that is, the condition being tested can result in one of only two %u201Ctruth values%u201D, %u201Ctrue%u201D or %u201Cfalse%u201D (but not both, nor neither). It is like 2 faces of a coin, which when tossed lands flat with one of the 2 sides on top: either %u201Cheads%u201D or %u201Ctails%u201D (but not both, nor neither). Hence the term %u201Cboolean logic%u201D is used to describe computer's reasoning.

At the heart of a decision-making language construct is condition testing, and testing almost always involves using comparison (<, =, <) and logical (& - and, | - or) operators. Such operators manipulate constants, variables and expressions to return a boolean value which is called %u201Cevaluation of the conditional%u201D. We shall very soon informally define the terms we have used so far. As we saw above, a conditional is a logical expression comprised of several expressions combined with logical and comparison operators to finally evaluate to a boolean value: %u201Ctrue%u201D or %u201Cfalse%u201D. We assume you are already introduced to the terms %u201Cexpression%u201D and %u201Coperator%u201D.

This may sound complex, but in reality it's simple.

Here's a real-world conditional:

if the dog barks at the door

then (do a few things %u2013 get the leash: take him out: wait for him to do his thing.)

else (do a few other things: get a rag to clean up the mess, yell at the dog, feel guilty.)


Your conditional is %u201Cif the dog barked at the door.%u201D It evaluates to a Boolean: either true or false. Depending on that Boolean, actions are taken. Oh, but comparison operators, you say! You didn't use those %u2013 surely they're far more complex.

So we'll give the dog a break. If he barks for longer than five minutes, let him out! The rest stays the same. There, now you've used a comparison operator: %u201C>%u201D (greater than.) Yes, it can get more complex (and fun!) as you'll see: let's begin to learn about those conditionals!

Our free content is sponsored by these ads become a prime member and get rid of them.
Test Your

Act now while we have available seating

Our on line school is private, affordable and interactive with trainer support.
Act now save your seat before someone else takes yours.
Act now