C Programming Tutorial For Beginners

Use these ands and we can also use else–if in order to check additional conditions so the and is used to check more than one.

Condition inside of the if parentheses and the else if is used to check another condition when this conditions false and so that is actually gonna work out pretty well now I want to show you guys a couple other things there’s a couple other things that we can do with these if statements so for example I’m gonna come down here and just show you guys some of these in addition to using that and we can also use something called or so I’m just gonna type out a simple if.

Statement I could say if 3 is greater than 2 and instead of using and like this I can use or and or is basically gonna allow us to check two conditions and the whole thing is going to be true if only one of those conditions true so I could say if 3 is greater than 2 or 2.

Is greater than 5 so only one of these is true right 3 is greater than 2 that’s true but 2 is not greater than 5 so this.

Guy’s false but when we use or one of these two conditions has to be true for the whole thing to be true so if I like printed something out here like true now when I run my program we should print true because we’re using that or and you see that we do but if I was to make this guy false so if I made this.

3 less than 2 now it’s not gonna print out true and we can just print out false so now we’re gonna.

End up renting out false because both of these guys are false so you can see down here we’re saying false so the difference between and and or when we have and like this both of these conditions have to be true in order for the.

Whole thing to be true and for us to execute this code when we have or only one of these guys has to be true so that’s kind of the difference there and I want to show you guys a couple other things that.

We can use so over here we’re using like a less than sign so for example if 3 is less than 2 I can also use a greater than sign I could use the less than or equal to sign I could use also a.

Greater than or equal to sign and if I.

Wanted to check for equality I could use a double I could use a double equals so the double equals will check to see if 3 is equal to 2 we can also use one more which is this exclamation point an.

Exclamation point basically means not equals so I could say if 3 is not equal to 2 then we’ll print out true so down here let’s run this and you’ll see that we get true so yeah there you.

Go one more thing I want to show you is how we can negate an entire operation so for example if I said 3 is greater than 2 this is gonna be true.

Right so we’d end up printing out true down here because 3 is greater than 2 but I could surround this whole thing with.

Parentheses and I could put an exclamation point right before this and this is called the negation operator and it’s basically going to negate whatever this ends up.

Being so this is true and we put this negation operator here this whole thing is going to be false.

And so now you’ll see because this is true and we’re using the negation operator we’re not going to end.