worker counting stocks in warehouse


There are times in programming where you need to check conditions against multiple items. If statements are used to do this a lot. We could do this by nesting if statements and performing the code if they return true as follows…

While this works, nesting can get hairy and confusing. There is a way that could be simpler. We can use the and (&&) operator to check two conditions. Here is a revision of the previous code…

The previous example shows how to compare two separate condition statements, but you can put together multiple conditions.

On a related note, you can also use the or (||) operator to utilize either/or logic.

Happy Coding!

Clay Hess

Share this post