Zombies + Binary #2

Programming Basics

Christopher Pitt
Zombies + Binary
3 min readNov 10, 2014

--

So I’ve always felt that once you see how important computing is for life you can’t just leave it as a blank box and assume that somebody reasonably competent and relatively benign will do something right with it. — Karen Spärck Jones

← Back | Forward →

Programming is a huge topic. There’s no way a single tutorial or series could teach much about it, but we only need to begin with a tiny amount of knowledge. How can we ask computers a question?

Asking Questions

The simplest way to ask questions is to give a computer a yes or no choice, and then tell it what we want to do if the answer is yes or no. That looks something like this:

This idea has many names, but two of the most common ones are if statement and control flow statement. They are both good names:

  1. The if keyword is special. It tells the computer that we want to analyse something to see whether it is true. In English: if this value is true then print “the value is yes” else print “the value is no”.
  2. There are two paths which this program can take. We control the flow of the program by making it take one of these paths. The value in $yes_or_no_value will determine which path the program takes.
Flow control →

$yes_or_no_value is a variable. It’s a placeholder for a value given elsewhere. We don’t need to know where or how it was given when we’re looking at the if statement. We can reduce this to a true/false value so that the rest of the examples are simpler:

Combining Questions

We can ask complex questions by adding a few of rules. We can ask a series of questions and have the program do something if they are all true:

In this example, we ask the program to print “all values are true” if each condition is true. As the last one is not, the program will print “at least one value is false”. When we combine many values with the and keyword, we tell the program to run the first print statement if the values are all true.

If we wanted to do something if only some of the values were true, then we could use another keyword:

In this example, the program will print “one of the values is true” because the second value is true. We can combine any number of and and or expressions together, and these rules will still apply.

The last new rule we will learn about is how to make values the opposite of what they are. Imagine we have a value that is true and we want it to mean false. We often say things like: “email me if my phone is not on” or “use the back door if the front door is not unlocked”.

Using not in a sentence makes something the opposite of what it was. We can do the same thing in programming:

We can even reuse one of our previous examples to see something more complex at work:

This time, the program will print “all values are true” because we’re asking it to when all the values are not false. The exclamation symbol (before a value) means we want false to be true and true to be false.

Simple Computers

Computers are simple machines. We can program them in exotic and expressive language but it is reduced to questions about true and false. Programming is mostly just complex string combinations and yes or no questions.

--

--