• 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 56 – Else-If Statement

November 20, 2018 by Caleb Curry 1 Comment

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

In this blog we are going to be discussing an extension to the if statement called the else if statement.  Now, the else if is different than the if else…Which is confusing because the names are so similar.  Soon I will go through all of the differences so you can have a clear definition of all three.

Else If is something you will want to use when you want to check for more than one thing with an if statement.   
 
For example, let’s say we have a variable, called temp.  

With an if and an else, we can check for two states…

This is useful, but with an if-else we are able to check for three or more states.

The key here is that it works just like a second if statement.  In fact, there is not any rules on what you have to test inside of the second condition.  You are allowed to use other variables or whatever you want.  Generally, though, you will be checking for the same thing in a different range. 

So, the easiest way to think about this is that the else at the end is appended to either the if statement or an if statement with the additional else if.  This is a “catch all” section that will always run if none of the other conditionals get ran.  

Now, it’s important to realize that only one section will ever get ran.  It’s not possible for both the if and the else-if to run!

Are you ready to read the next blog? Let’s go!

Filed Under: Uncategorized Tagged With: c programming, else-if statement, tutorial 56

Reader Interactions

Trackbacks

  1. C Programming Tutorial 56 – Else-If Statement | Nikkies Tutorials says:
    January 9, 2019 at 7:08 am

    […] Read the blog: https://www.calebcurry.com/c-programming-tutorial-56-else-if-statement/ […]

    Reply

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