if...else Statement

1 minutes
Share the link to this page
Copied
  Completed
The if/else statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed. The if/else statement is a part of PHP's "Conditional" Statements, which are used to perform different actions based on different conditions.

Transcript

Hello, in this video, we are going to take a look at the if else statement. So if you haven't already watched the if statement video, I highly recommend that you go and check that out. Okay, so we have these two conditions here, if the guess, you know is red, which is my favorite color, then we say Well done, you are so smart. If it isn't read or anything else is invalid, then he says incorrect. But with an if else statement, we only need to actually do that check once because technically, if this is not correct, then by default, this will be correct, because both of these notes are exclusive. So we only one of these can be correct at any given time.

So what we can do is get rid of this condition and print out here. We don't need to put any brackets because this isn't a condition so that what this says is if whatever condition is in here, this could be you know, not equal to the type checker version of regular The version is to be less than, which would be no is this value less than this one, you know, the close side is always the smaller side. That's basically how it works. So, if the guess is read, then say well done you also small otherwise, just fall back on this. So this is not a default. Essentially, if I run it again, correct me if I put red, which is the correct answer, my favorite color says well done.

You are so smart. So that is the if else statement. Nothing more to it than that nice little fallback. If you have any questions, feel free to pop me a video on pop me you know message and as usual, I look forward to seeing you in the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.