If/Else Statement

2.9 If/Else Statement

T-Plan Robot supports if/else statements with similar functionality and syntax used by Java. The format is:

if (<boolean expression>) {
    <commands>
else if (<boolean expression>) {
    <commands>
else {
    <commands>
}

The 'else if' and 'else' branches are optional. While the number of 'else if' branches are not limited, there can be just one 'else' construction. Note that the enclosing curly braces '{' and '}' must be on the same line as their associated if/else/else if keyword exactly as is displayed above.

The right curly brace '}' terminating the whole structured block is the only exception and it must be alone on a single line. Example:

# Look for an image on the remote desktop
Compareto "pattern.png" method="search"

# Exit if the image is not found,
if ({_EXIT_CODE} > 0) {
    Exit 1 

# If the image was found more times, take a screenshot and add a warning to the HTML report
else if ({_SEARCH_MATCH_COUNT} > 1) {
    Screenshot unexpected.png 
    Warning "Unexpected behavior - the template image was found {_SEARCH_MATCH_COUNT} times!" image=unexpected.png
}

If/else statements can be nested and combined with other constructions like the for statement as is usual in any other structured programming language.