Skip to main content
Question

Using Appian expressions, how would you generate a numeric triangle pattern?

A
Anonymous
December 11, 2025

Answer

You can nest one a!forEach() inside another to print patterns with several rows.


Appian Code

a!forEach(
items: enumerate(5) + 1,
expression: joinarray(
a!forEach(
items: enumerate(fv!item) + 1,
expression: fv!item
),
" "
)
)


Explanation


Step 1: enumerate(5) + 1

The pattern needs one item per row. enumerate(5) generates five numbers starting from zero:

{0, 1, 2, 3, 4}

Adding 1 gives:

{1, 2, 3, 4, 5}

These numbers are the five rows.


Step 2: The outer a!forEach()

a!forEach(
items: enumerate(5) + 1,
expression: ...
)

The outer loop takes one number at a time, and fv!item holds the current one: 1 on the first iteration, 2 on the second, and so on up to 5. The outer loop decides which row is being printed.


Step 3: The inner a!forEach()

a!forEach(
items: enumerate(fv!item) + 1,
expression: fv!item
)

The inner loop uses the outer loop’s current value to decide how many numbers to generate. When the outer value is 3, enumerate(3) + 1 generates {1, 2, 3}, and the inner loop returns each of those numbers.

Inside the inner loop, fv!item refers to the inner loop’s current item, not the outer loop’s item. The inner loop therefore counts from 1 up to the outer value instead of repeating the outer value.

Outer

fv!item

Inner output

1

{1}

2

{1, 2}

3

{1, 2, 3}

4

{1, 2, 3, 4}

5

{1, 2, 3, 4, 5}

Step 4: joinarray(..., " ")

joinarray() combines multiple values into one text string using a separator:

joinarray(innerArray, " ")

It turns each inner array into a space-separated string:

Inner array

After

joinarray

{1}

"1"

{1, 2}

"1 2"

{1, 2, 3}

"1 2 3"

{1, 2, 3, 4}

"1 2 3 4"

{1, 2, 3, 4, 5}

"1 2 3 4 5"

Without joinarray(), the inner loop would return an array of values instead of a single formatted string for each row.


Final output

The outer loop generates five rows, and the inner loop generates the numbers in each row:

Using Appian expressions, how would you generate a numeric triangle pattern?


Printing triangle star pattern

The star pattern uses the same structure.

a!forEach(
items: enumerate(5) + 1,
expression: joinarray(
a!forEach(
items: enumerate(fv!item) + 1,
expression: "*"
),
" "
)
)

The outer loop still produces the row numbers 1 to 5, and the inner loop still runs once per unit of the row number. The only change is that the inner loop returns "*" instead of the current number. When the outer value is 3, the inner loop runs three times and returns three stars, and joinarray() joins them with spaces into * * *.

The tables for the star version look like this:

Outer

fv!item

Inner output

After

joinarray

1

{"*"}

"*"

2

{"*", "*"}

"* *"

3

{"*", "*", "*"}

"* * *"

4

{"*", "*", "*", "*"}

"* * * *"

5

{"*", "*", "*", "*", "*"}

"* * * * *"


Final star pattern

*
* *
* * *
* * * *
* * * * *

For more coding challenges try : https://appianverse.com/coding

Try it yourself

Change the inputs or the expression and run it to see what it returns.

ri!n=
ri!isNumberic=

Independent evaluator: it approximates the Appian expression language and may differ from a real Appian environment. Verify anything that matters. Terms

JuniorExpressions#coding#sailcoding