Sitemap
Better Programming

Advice for programmers.

The Many Faces of “If” and How Programmers Misuse It

8 ways to use the conditional statement correctly

5 min readAug 24, 2021

--

Press enter or click to view image in full size
Person coding on a computer

What would programming be without the conditional if statement? Probably one of the most used logic checkpoints in all of programming, we would be lost without it. Unfortunately, as simple as it is to add this decision point to your code, it is not immune to misuse. In my 20 years as a programmer, I have seen some interesting mistakes by other programmers. In no particular order, here are eight examples based on real-life problems with “if” and possible reasons for why they happened.

1) If/Else on a Boolean

The basics of an if statement is to proceed into a block of logic when a condition evaluates to true. A complementary feature is the boolean data type, which is used to indicate true or false. They are often used together, but in this example, they shouldn’t be. The if/else logic isn’t necessary and the boolean value alone is sufficient. Here’s an example:

Possible reasons why this happened:

--

--

Responses (4)