ifelse(bool c, int x, int y): int

ifelse(bool c, var x, var y): var

Returns x when the expression or comparison c is true or nonzero, otherwise y.


c - any boolean expression.
x,y - any var or int.


x when c is true, otherwise y.


The returned variable type depends on the type of the arguments; for constants use a decimal point to mark them as var (f.i. 1 is int, but 1. is var).


var a = ifelse(x > y,x,y); // a is now the maximum of x and y

See also:

abs, min, max, between, sign, clamp, if

► latest version online