Nested IF/ELSE Conditional Statements
Yesterday I introduced If/Else Programming Logic. Today I’d like to show a more complicated example invloving nested conditional statements. What this means is that you can include If/Else statements within your If/Else statements to allow for even more complex programming logic.
Let’s look back at the example from yesterday but make it a bit more complex using nexted conditionals:
<?php
if ($newMember)
{
if($uniqueUserID)
{
$sendWelcomeEmail = True;
}
else
{
print "User name taken";
}
}
else
{
$sendWelcomeEmail = False;
print "Already a member!";
}
?>
This time, before deciding that we should send the welcome email, we add an extra if/else statement to verify that the user has selected a user name that is not already taken.
By now I am sure you are beginning to see that you will likely be using conditional statements in every program you ever write!
Leave a Reply