Syntax: if and else

The If statement will execute a list of statements when the expression is true. An else statement can be added to an if statement and will execute an alternative list of statements when the if statement is false. An if statement can be nested inside another if statement. The if statement allows a program to make decisions about which set of statements it should run.

You can include sets of if statements within other if statements, such statements are referred to as "nested".

You can test combinations of expressions by using && for "and" or || for "or" to join each expression which must be contained in its own set of brackets. The bar symbol is produced by pressing the shift key together with the key to the left of the "z".

Syntax:

if ( expression )
{
 list of statements
}

or

if ( expression )
{
 list of statements
}
else
{
 list of statements
}

or using && for AND and || for OR

if ( (expression1)&&(expression2)||(expression3) )
{
 list of statements
}
else
{
 list of statements
}

or nesting additional if statements within the main if (make sure you have all your closing brackets)

if ( expression )
{
 list of statements
 if ( expression )
 {
  list of statements
 }
}
else
{
 list of statements
}

Remarks:'

if – a keyword, used to start an if statement. The list of statements is only executed when the expression is true. An if statement can be nested inside another if statement – when you do this, it is good practice to indent your code to make it more readable.

else – a keyword, used to start a list of statements when the if expression is false.

list of statements – any valid OpusScript statements.

( ) – expressions must be surrounded by round brackets.

{ } – a list of statements must be surrounded by curly brackets.

image\Script_Button.jpgExamples