if

An control flow logic function used to execute an instruction or a block of instructions only if a condition is fulfilled. If the condition in the parentheses following the if is true, the instructions are executed.

Copy code
if( <i>expression</i> ) <i>statement1</i>;

or

if( <i>expression</i> ) <i>statement1</i>;
else<i>statement2</i> ;

Example

The following example checks whether characters with the ascii values 107 and 22 are alpha-numeric.

The if statement tests whether isalpha returns a non-zero value. If it does, the value is alpha-numeric. If not, the else clause prints a suitable message.

Copy code
    if (isalpha(107))
        lr_output_message ("The value 107 is %c", 107);
    else
        lr_output_message ("The value 107 is non-alphabetic");
    if (isalpha(22))
        lr_output_message ("The value 22 is %c", 22);
    else
        lr_output_message ("The value 22 is non-alphabetic");
Example: Output: 
Action.c(4): The value 107 is k
Action.c(11): The value 22 is non-alphabetic