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

Food & Beverage Marketing: How Ingredient Buyers Decide

Food & Beverage Marketing: How Ingredient Buyers Decide

Choosing an ingredient supplier is one of the higher-stakes decisions a food or beverage company makes. It runs through several people over a cycle that can stretch for months, and the deciding factor is usually how much risk each option carries for a business that cannot afford a line stoppage or a recall. For marketing[...]
How to Build a B2B Lead Nurturing Program That Closes Deals

How to Build a B2B Lead Nurturing Program That Closes Deals

Most B2B marketing teams are better at generating leads than keeping them warm. A form gets filled out, the lead lands in the CRM, and nothing happens until a salesperson gets around to it, by which point the buyer has moved on or gone quiet. In a market where the average deal takes months of[...]
How We Took the Grind Out of Link Building Prospecting

How We Took the Grind Out of Link Building Prospecting

Most link building programs stall at the same point, the prospecting spreadsheet. Finding sites worth pitching means pulling competitor backlinks, cross-checking them against what you already know, throwing out the junk, and judging what's left for relevance and quality. It's a few hours of repetitive work before a single outreach email gets written, and when[...]
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