Siebel eScript Language Reference > Siebel eScript Language Overview > eScript Statements >

if Statement


The if statement tests a condition and proceeds depending on the result.

Syntax A

if (condition)

statement;

Syntax B

if (condition)

{

statement_block;

}

[else [if (condition)

{

statement_block;

}]

[else

{

statement_block;]

}]

Placeholder
Description
condition
An expression that evaluates to true or false
statement_block
One or more statements or methods to be executed if expression is true

Returns

Not applicable

Usage

The if statement is the most commonly used mechanism for making decisions in a program. When multiple statements are required, use the block version (Syntax B) of the if statement. When expression is true, the statement or statement_block following it is executed. Otherwise, it is skipped.

The following fragment is an example of an if statement:

if ( i < 10 )
{
   TheApplication().RaiseErrorText("i is smaller than 10.");
}

Note that the brackets are not required if only a single statement is to be executed if condition is true. You may use them for clarity.

The else statement is an extension of the if statement. It allows you to tell your program to do something else if the condition in the if statement was found to be false.

In Siebel eScript code, the else statement looks like this, if only one action is to be taken in either circumstance:

if ( i < 10 )
   TheApplication().RaiseErrorText("i is smaller than 10.");
else
   TheApplication().RaiseErrorText("i is not smaller than 10.");

If you want more than one statement to be executed for any of the alternatives, you must group the statements with brackets, like this:

if ( i < 10 )
{
   TheApplication().RaiseErrorText("i is smaller than 10.");
   i += 10;
}
else
{
   i -= 5;
   TheApplication().RaiseErrorText("i is not smaller than 10.");

}

To make more complex decisions, an else clause can be combined with an if statement to match one of a number of possible conditions.

Example

The following fragment illustrates using else with if. For another example, read setTime() Method.

if ( i < 10 )
{
   //check to see if I is less than or greater than 0
   if ( i < 0 )
{
      TheApplication().RaiseErrorText("i is negative; so it's " +
         "less than 10.");
}
   else if ( i > 10 )
{
      TheApplication().RaiseErrorText("i is greater than 10.");
}
else
{
   TheApplication().RaiseErrorText("i is 10.");
}

See Also

switch Statement


 Siebel eScript Language Reference 
 Published: 18 April 2003