‘if’ and ‘switch’ statements

‘if’ statement for LoadRunner

In LoadRunner, “if” is a conditional statement with syntax identical to a conditional statement in C. The conditional statement regulates the flow of the script while the set condition is being evaluated.

The ‘if’ statement in LoadRunner helps with flow management by checking the correctness of the response and indicating whether a transaction succeeds or fails. You need to modify the code to achieve that goal.

Conditional expressions

1. If statement:

Compares the value of a variable with the specified condition and controls the flow based on the result (True or False). The subsequent statement or statements enclosed in braces are executed only if the condition is met. The next statement or statements enclosed in braces are ignored and execution continues if the condition fails.

Example:

Screenshot (228).png

2. ‘If-else’ statement:

This statement consists of two parts. The instructions in the second part are executed automatically if the condition in the first part is not met. Standard declarations are found in the ‘other’ section. You can write right after “else” if there is only one line of instruction code. However, if you have many declarations, you must enclose them in braces. Braces start immediately after the word “other”.

Example:

LoadRunner if else statement

3. “If-(else-if-…)-else” statement:

Use else-if to assess your numerous circumstances and make appropriate statements. The standard statement can be found in the last ‘else’.

Example:

LoadRunner if else if condition

4. Statement of “case change”:

Another control flow statement eliminates the need for numerous else-if statements when there are many instances. A specific case is executed depending on the value of the parameter. In the event that none of the matches to the specified cases succeed, “switch-case” also provides a default statement. Unlike switch-case, where you only need to write one expression to cover multiple scenarios, if-else requires you to write multiple if-else statements and expressions based on the condition. Let’s see how “switch-case” can be applied to the above example.

Example:

https://www.perfmatrix.com/wp-content/uploads/2020/01/LoadRunner_FlowLogic_Switch_Condition.png

    These are statements that determine the direction of execution by analyzing the situation. In addition to the syntax for conditional statements, you should be familiar with relational operators. The condition expression is written using these operators.

< less than

<= less than or equal to

> greater than

>= greater than or equal to

== equal to

!= not equal to

Scroll to Top