TERNARY
1g 2024-01-04 laplante@plcb.ca GOWEB/Languagetitle: “GoWeb TERNARY Operator” author: “Pierre Laplante” date: 2025-08-30 version: “1.0.0” section: “1g”
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.
The general syntax of the ternary operator is:
a := (logical expression) ? expression1 : expression2;
true
, a
will receive the value of expression1
.expression2
.res={
x := 1;
y := (x == 2) ? 5 : 7;
y;
z := (x == 1) ? 5 : 7;
z;
}
Result:
res=75.
res={
x := 1;
y := 0;
y = (x == 2) ? 5 : 7;
y;
y = (x == 1) ? 5 : 7;
y;
}
Result:
res=75.
res={
x := 1;
y := 2;
z := (x == 1) ? y*2 : y*3;
z;
}
Result:
res=4.