You can place or nest an If statement inside another If statement. When you nest If statements, you can check for a condition only when another condition is found to be true. When the first condition is found to be true, JAWS evaluates the nested If statement. JAWS evaluates it just as it would do for any other If statement. Thus, if the condition in the nested If statement is found to be true, JAWS performs any statements following the If statement.
You can use the Else key word within the nested If statement structure. You can also add any number of ElIf statements to the nested If statement structure.
When you nest If statements, you should use indentation. Using indentation makes it easier to match the If, Else, Elif, and EndIf keywords up with each other. Thus, you can be assured you have an EndIf that corresponds to each If key word.
Note: You can add any number of nested If statements within your scripts and functions. However, the more nested If statements you add, the harder your scripts are to debug when errors are encountered at compilation time. You should try to limit nesting If statements to one or two levels.
Var
Int iValue
Let iValue = CalculateNumber (); Assign a number to iValue
If iValue > 4 Then
If iValue == 5 Then
SayFormattedMessage (OT_MESSAGE, "The value is 5")
ElIf iValue == 7 Then
SayFormattedMessage (OT_MESSAGE, "The value is 7")
Else
SayFormattedMessage (OT_MESSAGE, "The value is greater than 4 but is not equal to 5 or 7")
EndIf; complete the nested If statement
Else
SayFormattedMessage (OT_MESSAGE, "The value is less than or equal to 4")
EndIf; complete the outer If statement
In the above example, JAWS performs the CalculateNumber function and stores the result in the iValue local variable.
Regardless of the number stored in iValue, JAWS will speak one of the above messages.