Conditionals 1 - 'if'

49:40 AS3 FLA 9

Prerequisite:

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: “If the dog needs to go out, let him out. Else he will pee on the floor.” 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 seatings

Our online school is private, afforable 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 – 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:

• If

• if-else

• if-else if-else

• Nested if, if-else and if-else if-else clauses

• 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 “computer programming,” 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 “decision making” in computer programming is often called “branching”. In modern computers, logical branching is boolean in nature; that is, the condition being tested can result in one of only two “truth values”, “true” or “false” (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 “heads” or “tails” (but not both, nor neither). Hence the term “boolean logic” 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 “evaluation of the conditional”. 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: “true” or “false”. We assume you are already introduced to the terms “expression” and “operator”.

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 – 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.)

Explanation:

Your conditional is “if the dog barked at the door.” 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 – 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: “>” (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 sponsered by these ads become a prime member and get rid of them.
Download
Source
Test Your
Skills

Act now while we have available seatings

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