Skip to content
Home Blog Web Design Complex Conditional Statements

Complex Conditional Statements

  • Web Design
Blueprint Digital
Blueprint Digital

Insights from the Blueprint Digital team.

“If I had won the lottery, I would have bought a boat.” In this sentence, it is impossible for the condition to be fulfilled, because it refers to an event in the past. I neither won the lottery, nor bought a boat.

Like the English language, programming languages make extensive use of conditional statements. When writing programming functions, conditional clauses are always given a boolean value of true or false. If the sentence in the lottery example was implemented into code in a conditional statement, it would return ‘false’, because neither condition can be fulfilled.

Web developers and other programers can combine multiple conditional clauses to make complex conditional statements. For example, suppose I have two php values called $p and $q, with values of “2=2” and “3=5”, respectively. $p is true and $q is false. I can compare these expressions with ‘and’ and ‘or’. $p AND $q returns ‘false’, because something cannot be both true and false simultaneously. The statement $p OR $q returns ‘true’, because at least one of the statements is true.

Conditionals become increasingly difficult when one or more ‘NOT’ clauses is present. A truth table can aid in deciphering the logic behind these complex conditional statements.

p q p AND q p OR q NOT (p OR q) NOT p NOT q (NOT p) OR (NOT q)
T T T T F F F F
T F F T T F T T
F T F T T T F T
F F F F T T T T

 

If you know the boolean value for both p and q, you can apply them to the table. For example, if you are looking to solve for either NOT p or NOT q, and p and q are both true, the conditional would return false, as indicated by the first line of the table. Truth tables are a handy way of quickly determining the outcome of your conditional statement.

Ready to Dominate Online and Grow Your Business?

Schedule time to connect with Blueprint about your online goals, or request a free review of marketing campaigns.

Related Posts

What Is Automated Lead Follow-Up and How Does It Work

What Is Automated Lead Follow-Up and How Does It Work

A new lead fills out a form, then waits. If the phone stays silent for a day, that lead has usually moved on to whoever answered first. Automated lead follow-up closes the gap. It is a marketing automation system that responds to every new inquiry within minutes, then continues the conversation through scheduled texts, emails,[...]
Free Advertising for Nonprofits Through Google Ad Grants

Free Advertising for Nonprofits Through Google Ad Grants

Advertising is usually the first line cut from a nonprofit budget, and the one that quietly costs the most to lose. Donors still search, scroll, and read, whether or not the cause has money to meet them there. Free advertising for nonprofits means promoting a cause without paying for placements, and it is how organizations[...]
Lead Scoring for B2B: How to Decide Which Leads Your Sales Team Chases

Lead Scoring for B2B: How to Decide Which Leads Your Sales Team Chases

Every marketing team has handed sales a list of leads that went nowhere. After a few of those lists, sales stops trusting them, works its own referrals instead, and the two teams settle into a standing argument about lead quality. Underneath the argument is a simpler problem: nobody has written down what a good lead[...]
Previous
Next

Partner with BLUEPRINT to reach your online goals, grow your business and reshape your story.

Get in touch with BLUEPRINT

Reach out to request a discovery call, a free campaign review, or for all other inquiries.

Subscribe to our newsletter