How do you define “if” for computers?

426 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

Your questions might be interpreted in a variety of ways, I’m not sure how to approach them the way you want but since you’re not a programmer, I’ll go with something basic.

The first thing I can think of is “loops”. A program (or parts of it) can be made to run in loops, as in repeating an action again and again until an exit condition is met. This can be utilized in a way, like checking “if x has occurred” every time the code loops.

The instructions would look like

– loop this segment of code until y is completed:
– check if x occurred:
– yes: then complete y
– no: then do nothing

Assume this loop executes every 100ms, this would ensure you will be completing y in around ~100ms after x occurs. You don’t know when x is going to occur, but your program would catch it during the first iteration once it does. This way your program is able to wait for a future input, or at least act like it’s waiting for it.

You might also want to check out [event-driven programming.](https://en.wikipedia.org/wiki/Event-driven_programming)

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