Skip to main content
Conditional logic is the foundation of dynamic behavior in penscript. These operators control which content appears, which rules apply, and which branches a workflow follows.

Conditional: :if

Evaluates a condition and returns one of two branches.
The condition can be a variable, an inline expression, or another operator:
Multiple conditions can be passed as an array — all must be true for the :then branch:
The return values can be any type — strings, numbers, objects, arrays, or nested operators:

Switch: :case

Matches a value against a list of options. Returns the result for the first match, or the :else fallback if nothing matches.
Cleaner than nested :if chains when you have multiple known values to match against.

Comparison: :cmp

Compares a value against one or more thresholds. Returns true or false. Supported modifiers: Single threshold:
Multiple thresholds — all must be satisfied:
Most commonly used as the condition inside :if:
Works with numbers, dates, and values produced by pipes like | age.

Equality: :eq

Tests whether all values in a list are equal to each other.
Useful for validating that multiple fields contain the same value (e.g., password confirmation, duplicate detection).

Uniqueness: :distinct

Returns true if all values in the list are different from each other.
Useful for dynamic validation — ensuring all generated fields have unique values:

Membership: :in / :nin

Tests whether a value exists (or doesn’t exist) in a given list. :in — value is in the list:
:nin — value is NOT in the list:
Works naturally with :if for access control and routing:

Boolean Helpers

:not

Negates a boolean value.

:every

Returns true if every item in an array satisfies a condition. The condition is evaluated for each item with @item as the current element.

:some

Returns true if at least one item satisfies a condition.

Logical Constants

Explicit boolean and null values for use in expressions where you need to return a fixed value.
These are typically used inside :if branches or :map transformations when you need to produce a specific constant value programmatically.

Next Steps

Variables & scope

Variable references and scope

Numbers & calculations

Arithmetic and formatting

Loops & arrays

Working with collections

How penscript works

Expression modes and composition