if Statement

Action

Executes particular statements depending on the value of a condition.

Syntax

if boolean-expr
  statement
else
  statement
Variable Description
boolean-expr A boolean expression.
statement A single statement, or a series of statements.

Notes

If the value of the boolean expression is TRUE, the statement immediately below it is executed. If the value of the boolean expression is FALSE, control passes to the else clause, if any. If there is no else clause in an if statement, and if boolean-expr is FALSE, statement is not executed, and control passes to the next statement in the script, which could be another if statement. If you are trying to test multiple conditions, then you should use a select or switch statement. You could use nested if..else statements, but if you have more than two or three conditions, the levels of indentation will become cumbersome. Micro Focus recommends that you avoid using if..else if..else statements. Using 'else if' will make it difficult to troubleshoot exceptions that occur in the code block because the results file will always point to the first 'if' statement even if it was actually a subsequent 'if' statement that raised the exception.

Example

[-] testcase ifExample()
	[ ] INTEGER i = 1, j = 2
	[ ] BOOLEAN b = TRUE
	[-] if(i == j)
		[ ] Print("Equal")
	[-] else
		[ ] Print("Not Equal")
	[ ] Print("Not even in the ballpark!")
	[-] if(b)
		[ ] Print("TRUE")
	[ ] // Prints:
	[ ] // Not Equal
	[ ] // Not even in the ballpark!
	[ ] // TRUE