NEW IF STATEMENT - NESTED IF STATEMENT

Modified on Wed, Dec 13, 2023 at 11:31 AM

How to Use Conditional !if Statements


Introduction

Conditional !if statements allow you to define logic that can execute different text blocks based

on certain conditions. This is particularly useful for creating dynamic content that changes

based on the values of variables, which are represented by block names surrounded by curly

braces (e.g., {City} or {First Name}).


Basic Structure

The basic structure of a conditional !if statement is as follows:


!if "condition" !then!

outcome if condition is true

!else!

outcome if condition is false

if!


Nesting

Nesting allows you to evaluate conditions within conditions. This is useful when you have

multiple criteria that affect the outcome.


Absence of !else!

If an !else! statement is not included and the !then! condition evaluates to false, an empty

string is returned by default.


Multiline Statements

For readability, especially with nested conditions, you can put parts of your statement on

different lines.


Examples


Basic Example

!if "{City}"="Toronto" !then!

The city is Toronto.

!else!

The city is not Toronto.

if!


Nested Example

!if "{City}"="Toronto" !then!

!if "{Province}"="ON" !then!

Toronto is in Ontario.

!else!

Toronto is not in Ontario.

if!

!else!

This is not Toronto.

if!


In this example, the inner !if checks the province only if the city is Toronto.


Multiline and Complex Nesting

You can write the same nested example with parts on different lines for clarity:

!if "{City}"="Toronto" !then!

!if "{Province}"="ON" !then!

Toronto is in Ontario.

!else!

Toronto is not in Ontario.

if!

!else!

!if "{Province}"="ON" !then!

This is a city in Ontario, but not Toronto.

!else!

This is a city outside Ontario.

if!

if!


Notes

 Always ensure !if has a matching if!.

 Conditions are written as "variable"="value".

 Nested !if statements are processed based on the result of their parent !if.

 Since multi-line coding and extra spacing is allowed, to actually print a space

surrounding the various keywords (!if !then! !else! if!) use <space> to indicate 1 space.

Using <space>

{Address}<space>!if "{City}"="Toronto" !then!

The city is Toronto.<space>

!else!

The city is not Toronto.<space>

if!{Country}<space>


By following these structures, you can create complex logical expressions that cater to various

scenarios and user inputs. Remember to test your conditions to ensure they are set up

correctly.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article