Statements: if else

The if-else statement allows conditional execution of statements.

Syntax

Form 1:

if(condition)statement‑1

Form 2:

if(condition)statement‑1elsestatement‑2

Discussion

The if statement executes the nested statement-1 if the condition evaluates to the boolean value true. If the condition evaluates to the value false and the else clause exists, the nested statement-2 is executed. To execute multiple statements, you can group those together within a block statement. For example:

var bool isSelected = ...; // If the component is selected, the label and the icon should appear // with full intensity if ( isSelected ) { SomeLabelTextView.Color = #FFFFFFFF; SomeIconImageView.Opacity = 255; } // If the component is not selected, the label and the icon should appear // pale. else { SomeLabelTextView.Color = #FFFFFF77; SomeIconImageView.Opacity = 128; }

When nesting if statements and else clauses, the Chora compiler resolves ambiguities by associating each else with the closest if that lacks an else. To clarify your intent, you should group the statements and clauses into block statements.