Skip to content
Home Blog Web Design Complex Conditional Statements

Complex Conditional Statements

  • Web Design
Blueprint Digital
Blueprint Digital

“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

How We Helped A Healthcare Company Reposition Their Brand

How We Helped A Healthcare Company Reposition Their Brand

After a car accident, the search for care starts within minutes, on a phone, before the shock wears off, and the patient commits to the first brand that reads as competent, calm, and ready to take the whole problem off their hands. In personal-injury healthcare, the brand that wins at first contact wins the rest:[...]
The B2B Lead Generation Funnel: From First Touch to Closed Deal

The B2B Lead Generation Funnel: From First Touch to Closed Deal

Most B2B marketing teams can generate leads. Fewer can predict them. The month a big trade show or a strong campaign lands, the pipeline looks healthy; through the quiet months that follow, sales starts asking where the opportunities went. The difference between a lucky pipeline and a predictable one is whether you treat lead generation[...]
Creating Better and Faster Landing Pages with AI

Creating Better and Faster Landing Pages with AI

Landing pages have always been one of the most important assets in a performance marketing program. They can support SEO campaigns, email campaigns, sales enablement, product launches, event promotion, and plenty of other initiatives. But for teams focused on paid media and lead generation, landing pages carry even more weight because they often determine whether[...]
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