‘if’ statement in LoadRunner

‘if’ is a conditional statement in LoadRunner and its syntax is as same as C language conditional statement. The conditional statement evaluates the given condition and controls the flow of the script.

Along with flow control task, LoadRunner ‘if’ statement also helps to check the correctness of response and marks a transaction Pass or Fail. For that purpose, you need to tweak the code.

Conditional Statements

1. ‘if’ statement:

It evaluates the value of a variable against the given condition and controls the flow as per the output (True or False). If the condition is fulfiled then only the next statement or statements enclosed by curly braces are executed. In case of failure of condition, the next statement or statements enclosed by curly braces are skipped and continue the execution.


LoadRunner if condition
Figure 01: Flow Control using ‘if’ condition

2. ‘if-else’ statement:

This statement has two parts. If the condition of the first part does not fulfil then the statements written in the second part will execute automatically. The ‘else’ part contains the default statements. If there is only one line statement then you can write just after the ‘else’. On the other hand, if you have more than one statements then enclose them in a curly-brace. The curly-brace will start just after ‘else’ word.


LoadRunner if else statement
Figure 02: Flow Control using ‘if-else’ condition

3. ‘if-(else-if……)-else’ statement:

If you have multiple conditions then use else-if to evaluate those conditions and execute the respective statements. The last ‘else’ contains the default statement.


LoadRunner if else if condition
Figure 03: Flow control using if-(else-if….)-else condition

4. ‘Switch-Case’ statement:

Another type of flow control statement which saves you to write multiple else-if statements when you have a large number of cases. Based on the value of the parameter, a particular case is executed. ‘switch-case’ also has a default statement in case of failure of any matches with the given cases. In ‘if-else’, you need to write multiple ‘if-else’ statements and expression based on the condition but in ‘switch-case’ you need to write only one expression for the multiple cases. Let’s see how ‘switch-case’ can be used in the above-given example?


Figure 04: Flow control using ‘switch-case’ statement

These are the flow control statement which directs the execution by evaluating the condition. Along with the syntax of the conditional statement, you should also know the relational operators. These operators are used to write the expression of the condition.

< less than

<= less than or equal to

> greater than

>= greater than or equal to

== equal to

!= not equal to

Leave a Comment