Member-only story
Here’s How the CPU Handles If Statements and Branching
Know why if statements are disliked and how they actually work. Spoiler: they aren’t that bad
These days, there seems to be a holy war going on against if statements and branch programming in the software development community. Branching consists in altering the control flow of a program by switching to another sequence of instructions. The simplest example we’re all familiar with is the use of if statements:
Now, branching and if statements are a staple of programming and have been around since ever. Through the decades they acquired a bad reputation, though; countless YouTube videos, blog posts, and articles talk about why you should avoid using them like the plague. Because of this, I guess most people despise branching just because they heard it’s bad, without really knowing what they’re talking about.
In this article I’m going through the why and when this practice is considered inefficient. I will also provide some alternatives and contexts in which branching is…