Search:

Home | Programming | Php


If/Else Programming Logic

By: Deceth

It's time to start introducing some more complex programming logic today! Conditional statements are still fairly simple to understand but allow for much more complex capabilities than I have demonstrated thus far. For example, while creating variables is useful, we quickly find ourselves limited in the types of applications we can make without further logic. Conditional statements allow us to include some very basic artificial intelligence into our programs by allowing the software to make certain decisions on its own based on the values of variables.

Please keep in mind that while I am demonstrating this in the context of PHP, IF/ELSE statements are a fundamental component of most programming languages.

So how does the computer make a decision? Basically, you provide a statement and then the system will verify whether that statement is true of false. Depending on the result, a different path of code will be executed. Here is an example:

<?php
if ($newMember)
{
$sendWelcomeEmail = True;
}
else
{
$sendWelcomeEmail = False;
print "Already a member!";
}
?>


Imagine you are signing up to become a member of a website. Some function not shown will likely check the email address you provide to determine if you are already a member of the website of not. This function would then set the value of the variable $newMember to either True of False. The code above then decides if a welcome email should be sent to the user or not depending on if they are already a member of the website or not.

Again note that the function to actually send the email is not shown, but we assume that this function would take the variable $sendWelcomeEmail as a parameter and use this to determine whether or not to send the email.

Article Source: http://www.writerdatabase.com

www.webdevnotes.com/ifelse-programming-logic/

Please Rate this Article

 

Not yet Rated

Click the XML Icon Above to Receive PHP Articles Via RSS!

Powered by Article Dashboard