Coding 101: If/Else Statements Simplified

The Test Lead
4 min readSep 21, 2021

This article will try to simplify the concept of If/Else statements in computer science programming. An if/else statement is an example of a conditional statement. If a certain condition is met, then an action will take place. You use if/else statements every day in your life without realizing it. See the below flowchart as an example.

The current situation is that you are hungry. Next, we will see if you have food. If you do have food, you will just eat the food you already have. Else, you will go buy some food to eat. This is a basic example of an if statement.

In computer science, just like in real life as seen in our flowchart, in an if statement, if a certain condition is met then a specific action will take place. If that condition is not met then that action will not take place and another action may take place instead.

The above line of code demonstrates what was earlier shown in our flowchart. We know that we are hungry. Our if statement checks if we have food. Because “doIHaveFood” is equal to true then this block of code will print “Eat the food that I already have”. If “doIHaveFood” was equal to false, the code would print out “Go buy some…

--

--

The Test Lead

SDET at fintech company in NYC. Visit personal page http://thetestinglead.com// Twitter @juss_bailey Youtube @The Test Lead