Synopsis: if (condition) then_part [ else else_part ]
Depending on condition only one of the code
branches then_part and
else_part is executed. The
else_part is optional and may be omitted. Both
then_part and
else_part may either be single statements or a
sequence of statements enclosed in curly brackets, i.e. a block. The
then_part is executed if and only if
condition evaluates to true
,
the else_part otherwise. It is an error if
condition evaluates to something other than
true
or false
.
Example 8.4. Conditional branch
{ integer a = 10; if ( a > 10 ) y2milestone("a is greater than 10"); else { // Multiple statements require a block... y2milestone("a is less than or equal to 10"); a = a * 10; } }
Example 8.5. Conditional branch with "else if
"
{ list &string& new_list = ["a", "new", "string"]; if (contains(new_list, "test")) y2milestone("this is a test"); else if (size(new_list) > 100) y2error("Too big list!"); else if (contains(new_list, "string")) y2milestone("this is a new list"); else y2error("Undefined behavior for list %1", new_list); }