Cold Help System: Programming: ColdC Reference Manual: Language Structure: Expressions: Operators: Conditional


The || and && operators act as logical OR and AND operators, respectively. The expression (this || that) is equivalent to this OR that, where the return value of the expression is this if this is logically true. If this is not logically true then the return value of the expression is that.

The expression (this && that) is equivalent to this AND that, where the return value of the expression is logically true when both this and that are also logically true. If either this or that are not logically true then the return value is false.

ColdC's conditional operators are short-circuit operators, meaning that the right-hand argument is never evaluated if the left-hand argument is sufficient to determine the value of the expression. This is important if the right-hand argument has side-effects or could cause an error. For instance, because of this it is possible to have the following expression:

(| dict[key] |) || throw(~nope, "Nope, doesn't exist");

With this expression if key is in the dictionary dict then the return value is the related value to key. If it is not, the error ~keynf is thrown by the index operator ([]). However, the expression is a critical expression. Because of this the left value becomes ~keynf, which is logically false, and the interpreter moves onto the throw function.

The ? : operator is a trinary operator, with the following syntax:

condition ? true-expr : false-expr

The result of this expression is the result of true-expr if condition is true, or the result of false-expr if condition is false. This is similar to the Conditional if-else Statement.


Operator Precedence | Index Operators | Arithmetic Operators | Assignments | Logical Operators | Conditional | List Splice Operator


the Cold Dark