TERNARY 1g 2024-01-04 laplante@plcb.ca GOWEB/Language


title: “GoWeb TERNARY Operator” author: “Pierre Laplante” date: 2025-08-30 version: “1.0.0” section: “1g”

module: “Goweb/Language”

Name

This document explains how the ternary operator works in GoWeb.
It can be used in both variable declarations and assignments, but not as a standalone expression.

Description

The general syntax of the ternary operator is:

a := (logical expression) ? expression1 : expression2;

Examples

Example 1: Declaration with ternary

res={ 
    x := 1;

    y := (x == 2) ? 5 : 7;
    y;

    z := (x == 1) ? 5 : 7;
    z;
}

Result:

res=75.

Example 2: Assignment with ternary

res={ 
    x := 1;
    y := 0;

    y = (x == 2) ? 5 : 7;
    y;

    y = (x == 1) ? 5 : 7;
    y;
}

Result:

res=75.

Example 3: Ternary with an expression

res={ 
    x := 1;
    y := 2;

    z := (x == 1) ? y*2 : y*3;
    z;
}

Result:

res=4.

See Also

Version