How do you define “if” for computers?

429 views

I’m not a programmer, how do you get from binary 1s and 0s to “if x occurs complete y” How do you tell the computer to wait for a future input?

In: 2

11 Answers

Anonymous 0 Comments

You understand that everything the computer does is arithmetic, right? Manipulation of numbers? In particular, the list of instructions is numbered (as illustrated by u/Slypenslyde’s answer), and the CPU has a number stored in its memory that tells it which instruction it is supposed to execute next.

If you’re trying to tell the computer to do something like `If c is 1, then go to instruction number n; if c is 0, then go to instruction number m instead`, then the way to do that without an “if” is to tell it `Go to instruction number (n*c+m*(1-c))`.

If this instruction is, itself, instruction number m, then the computer is just going to keep executing the instruction “Go to instruction number m” over and over until c becomes true, and then will go to instruction n. So effectively the computer will “wait” for c to become true before it acts.

You are viewing 1 out of 11 answers, click here to view all answers.