• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Caleb Curry

Making Money and Investing

  • Home
  • Make Money Online
  • How to Buy Bitcoin
  • Get Started with Real Estate Investing
  • How to Start a Website
  • Courses
    • Full Time Income Online
  • Sponsorship

C Programming Tutorial 53 – Evaluating Complex Conditionals

November 19, 2018 by Caleb Curry Leave a Comment

In the last blog we went over Logical Operators! Check it out first! Are you new here? Start at the beginning, Intro to C!

This blog we are going to be discussing complex conditionals. First, you let’s do a brief review of conditionals. A conditional is something that evaluates to true or false. Inside of a conditional you can have relational operators. Let’s say we have a variable, x, which has the value 5. We can make a conditional like this:

x < 5.  This is the equivalent of saying 5 < 5, which would evaluate to false. 

Let’s say we have another example of x > 1, which would evaluate to true.   

With complex conditionals, we combine multiple conditionals. So we can say something like x < 5 OR x > 1. The final result ultimately depends on the operator I the middle, which is known as a logical operator.

We’ve discussed those in more detail in the last video, so the point of this video is to practice evaluating more complex conditionals. It’s super important to be able to read these because if you can’t you might have code that is not checking for what it is supposed to be checking for.

There are really two ways to analyze conditionals. The first is if we know the values of any variables. This allows us to work through the process and come up with a final truth-value. The second is if we do not know the values of the variables. In this situation, we write down all possible paths. The process of writing all possible paths is done with a truth table.

First, we will start with knowing the value of the variables.

We can work our way from the inside out to evaluate this expression.  

Most of the time you are not going to know the values of these variables ahead of time, or else there is no point in running a conditional. Because of this, you will want to learn how to think about these conditionals without giving direct values to variables. Consider the variables to have values that we asked from the user.

It’s also beneficial to look for ways to simplify our expression. 

For example, the last part has this: 

which could instead be written as: 

The middle section also has both x > 0 and x != 0.  The second one is unneeded because x > 0 includes checking x != 0.

Read the next blog now!

Filed Under: Uncategorized Tagged With: c programming, evaluating complex conditionals, tutorial 53

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

my face to show my face

My name is Caleb Curry and I started my online business teaching software development and doing digital marketing for brands. Entrepreneurship has changed my life and has allowed me to earn a full time living from anywhere. I now have the freedom and energy to pursue skills and opportunities that I find interesting. This website is all about my journey.

Get my top Python Tips and Tricks

50+ Python Tips and Tricks!

Subscribe to our newsletter to get notes and latest content by email.

    We won't send you spam. Unsubscribe at any time.

    Follow Me!

    • Instagram
    • YouTube

    Recent Posts

    Copyright © 2021 · Genesis Sample on Genesis Framework · WordPress · Log in