Ternary operator ?: in AL

AL language now supports ternary (conditional) operator. The ternary operator? : known from other programming languages, streamlines conditional operations in code, enhances readability and reduces verbosity.

The following examples show how the code  GetBooleanText() can be rewritten using the ternary operator to be less verbose and more succint.

Without the ternary operator:

procedure GetBooleanText(b: Boolean): Text;
begin
    if b then
        exit('True')
    else
        exit('False');
end;

With the ternary operator

procedure GetBooleanString(b: Boolean): Text;
begin
    exit(b ? 'True' : 'False');
end;

Regards,
Tharanga Chandrasekara

Click on a star to rate it!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.